with temp as (
select '1' 标识,'2023-01-01' 日期,'a' 项目
union all select '1','2023-01-01','a'
union all select '2','2023-01-01','a'
union all select '2','2023-01-01','b'
union all select '3','2023-01-01','a'
union all select '3','2023-01-01','b'
union all select '3','2023-01-01','c'
union all select '4','2023-01-01','a'
union all select '4','2023-01-01','b'
union all select '4','2023-01-01','c'
union all select '4','2023-01-01','c'
union all select '4','2023-01-02','c'
)
select
*,
--相同并列数字
(DENSE_RANK() over(partition by 标识,日期 order by 项目)) DENSE_RANK相同并列数字,
--此位有跳跃
RANK() OVER(PARTITION BY 标识,日期 ORDER BY 项目 DESC) RANK此位有跳跃,
--分组后依旧按照顺序
(row_number() over(partition by 标识,日期 order by 项目)) row_number分组后依旧按照顺序
from
temp
order by
标识,日期,项目
查询结果图,主键为“标识和日期”,排序为“项目”