MySQL根据某字段分组(group by)之后再根据另外的字段排序(order by)

修改SQL写法如下:

select * from sensor_alarm s ,
(SELECT MAX(si.gmt_create) max_gmt_create,si.s_id FROM sensor_alarm si group by si.s_id ) s2
where s2.s_id = s.s_id AND s2.max_gmt_create = s.gmt_create 
ORDER BY s.gmt_create DESC 
LIMIT 0,10

发表评论

邮箱地址不会被公开。 必填项已用*标注