SQL分组排序语句

时间:2021-11-25 02:43:56

SQL分组排序语句

product_id是多个重复的,需求是每个product_id只取一条,并且id倒序排列。

SQL语句:SQL语句:

SELECT * from (

SELECT * from shop_product_snapshot GROUP BY product_id,id ORDER BY product_id,id DESC

) AS shop_product_snapshot GROUP by product_id ORDER BY `id` DESC