mysql 根据某一字段分组 每组取前20条
要求是每个device code作为一组 根据日期取出每个code的最新的前10条
回答
SELECT a.*FROM
( SELECT
w.*,
(SELECT count(*) + 1
FROM weld_alarm WHERE weld_alarm.code = w.code AND weld_alarm.id < w.id ) AS group_id FROM weld_alarm w
) a WHERE a.group_id <= 20 order by code
以上是 mysql 根据某一字段分组 每组取前20条 的全部内容, 来源链接: utcz.com/a/57206.html