MySql 分组排序取时间最大的一条记录

时间:2023-03-08 16:37:45
SELECT A.* FROM digital_asset A,
(SELECT name, max(last_updated) max_day FROM digital_asset GROUP BY name) B
WHERE A.name = B.name AND A.last_updated = B.max_day
 SELECT A . *
FROM bbs_threads A, ( SELECT digest, max( dateline ) max_dateline
FROM bbs_threads
WHERE fid =51
AND digest >0
AND displayorder >=0
GROUP BY digest
ORDER BY max_dateline
)B
WHERE A.digest = B.digest
AND A.dateline = B.max_dateline
LIMIT 0 , 20