Mysql5.7
先按supervise_type 分组,取出时间最大的一条,然后在根据 supervise_type 和 max(start_date) 去原表查询相同的记录。
Mysql8.0就可以直接用窗函数解决了
SELECT
a.id,
a.supervise_type,
a.start_date
FROM
t_inspect_round_copy1 a,
(
SELECT
b.supervise_type AS "supervise_type",
max( b.start_date ) AS "start_date"
FROM
t_inspect_round_copy1 b
WHERE
b.del_flag = '0'
AND b.`level` = '4'
GROUP BY
b.supervise_type
) d
WHERE
a.del_flag = '0'
AND a.`level` = '4'
AND d.supervise_type = a.supervise_type
AND a.start_date = d.start_date
ORDER BY
a.supervise_type ASC