Rumah >pembangunan bahagian belakang >tutorial php >mysql获取关联表下最新数据
目前最新的数据能获取到,但是我想要获取关联表b最新入库时间下的数据,在根据最新入库时间返回关联表a在当前最新入库时间下的数据,没有则返回0
我自己是这样写的
SELECT fang_time, city_name, IF(area is NULL,0,area), IF(taoshu is NULL,0,taoshu) FROM f_city AS fc LEFT JOIN (SELECT * FROM f_chengjiao ORDER by fang_time DESC) AS fcj USING (city_id) GROUP BY fc.city_id
SELECT fang_time, city_name, IF(AREA IS NULL,0,AREA) AS arra, IF(taoshu IS NULL,0,taoshu) AS taoshu
FROM f_city AS fc INNER JOIN
(SELECT * FROM f_chengjiao ORDER BY fang_time DESC) AS fcj
USING (city_id) ORDER BY fcj.fang_time DESC
你要的是不是这样的,如果不是欢迎追问。
SELECT fang_time, city_name, IF(AREA IS NULL,0,AREA) AS arra, IF(taoshu IS NULL,0,taoshu) AS taoshu
FROM f_city AS fc INNER JOIN
(SELECT * FROM f_chengjiao ORDER BY fang_time DESC) AS fcj
USING (city_id) ORDER BY fcj.fang_time DESC
你要的是不是这样的,如果不是欢迎追问。