这是我的SQL语句 实在编不下去了。。。
SELECT
custom_name,
think_houses.houses_name,
-- (SELECT custom_status_status FROM think_custom_status WHERE custom_custom_id=custom_id ORDER BY custom_status_status DESC LIMIT 0,1) as custom_status
FROM
think_custom
INNER JOIN think_houses ON think_custom.houses_houses_id = think_houses.houses_id
WHERE
`borker_borker_id` = '4'
LIMIT 0,
1
主要实现 从 think_custom_status 表中获取 custom_custom_id=custom_id 最大的一条的 custom_status_status 和 create_time
还有个更蛋疼的就是
从 think_custom_status 表中获取 custom_custom_id=custom_id 最大的一条的 custom_status_status 和 create_time 中custom_status_status =4的
这个 用一句sql 能不能实现 怎么实现? 还是只能去foreach
已经解决 谢谢Honwhy的帮助
SELECT `custom_name`,think_houses.houses_name,B.custom_status_status,`custom_id`,B.create_time FROM `think_custom` INNER JOIN think_houses ON think_custom.houses_houses_id = think_houses.houses_id LEFT JOIN (SELECT custom_custom_id,create_time,MAX(custom_status_status) AS custom_status_status FROM think_custom_status GROUP BY custom_custom_id) AS B ON B.custom_custom_id=think_custom.custom_id WHERE `borker_borker_id` = '4' AND `custom_status_status` = '0' LIMIT 0,2