SELECT * FROM
(
SELECT t2.*, t1.Id as t1id FROM table t1
LEFT JOIN table t2 ON tl.Id = t2.t1id
-- ORDER BY t2.time DESC DESC
HAVING 1 ORDER BY t2.time DESC
) t
GROUP BY t.t1id
这种是正确的 这里需要用having 后再 order by
-- 分组后 后取出每天最大时间一条的最新位置
(
select GROUP_CONCAT(DATE_FORMAT(b.time, '%m-%d %H),b.CityName ORDER BY b.time DESC)
)
as Location,
错误示例: 这种取到t2.*是未排序的 , max(t2.time) 取的是正确的 最大时间 但是要求是取分组后最大时间的那一整条
SELECT t2.*, max(t2.time) FROM table t1
LEFT JOIN table t2 ON tl.Id = t2.t1id
group by t1.id order by t2.time