SQL分组排序去重复的小实例
(编辑:jimmy 日期: 2024/11/15 浏览:3 次 )
复制代码 代码如下:
SELECT
*
FROM
(
SELECT
userid,
classid,
remark,
ROW_NUMBER () OVER (
PARTITION BY userid,
classid
ORDER BY
addtime DESC
) AS row_bank
FROM
Eng24VIPCourseIntention
) AS ta
WHERE
row_bank = 1
==========================
PARTITIONBYuserid,classid 这里是按什么分组, 注意一下。
SELECT
*
FROM
(
SELECT
userid,
classid,
remark,
ROW_NUMBER () OVER (
PARTITION BY userid,
classid
ORDER BY
addtime DESC
) AS row_bank
FROM
Eng24VIPCourseIntention
) AS ta
WHERE
row_bank = 1
==========================
PARTITIONBYuserid,classid 这里是按什么分组, 注意一下。
下一篇:解析sql中得到刚刚插入的数据的id