官网说明类似的支持:http://www.mysqltutorial.org/mysql-row_number/
根据说明排序 再根据条件判断是否一致 来决定是否新增 1
SELECT b.* FROM (
SELECT
(@row_number :=
CASE WHEN @region_id = region_id AND @oil_id = oil_id THEN
@row_number + 1 ELSE 1
END
) AS rn,
id,
oil_date,
(@region_id := region_id) AS region_id,
(@oil_id := oil_id) AS oil_id ,
last_update_time
FROM
`bwoil_prod_oil_price` s,
(SELECT @row_number:=0) AS t
WHERE audit_status=1 AND STATUS =0
ORDER BY region_id,oil_id ,oil_date DESC,last_update_time DESC
) a
INNER JOIN `bwoil_prod_oil_price` b ON a.id = b.id
WHERE a.rn = 1