SELECT t1.*FROM 表 t1INNER JOIN ( SELECT devicename, MAX(max_time) AS max_time FROM 表 GROUP BY devicename
) t2ON t1.devicename = t2.devicename AND t1.max_time = t2.max_time;
如果8.0支持开窗
SELECT devicename, max_time, other_columns
FROM (
SELECT devicename, max_time, other_columns,
ROW_NUMBER() OVER (PARTITION BY devicename ORDER BY max_time DESC) as rn
FROM 表
) t
WHERE t.rn = 1;