欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SQL分组排序语句

程序员文章站 2024-03-12 17:26:08
...

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