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
it
這種是正確的 這裏須要用having 後再 order byio
-- 分組後 後取出天天最大時間一條的最新位置table
(
select GROUP_CONCAT(DATE_FORMAT(b.time, '%m-%d %H),b.CityName ORDER BY b.time DESC)
)
class
as Location,select
錯誤示例: 這種取到t2.*是未排序的 , max(t2.time) 取的是正確的 最大時間 可是要求是取分組後最大時間的那一整條im
SELECT t2.*, max(t2.time) FROM table t1tab
LEFT JOIN table t2 ON tl.Id = t2.t1id
group by t1.id order by t2.time
di