我有一个包含4列的表格:Prctuid
,Puid
,PCode
和Code_Desc
我需要为每个Prctuid
选择10个记录,每个PCode
。
如果有5个Prcruid
包含2个Pcode
,而每个Pcode
都有多个Puid
,则输出应该有100条记录。
答案 0 :(得分:0)
您可以使用row_number
select
x.Prctuid
,x.Puid
,x.PCode
,x.Code_Desc
from
(select
*,
RN = row_number() over (partition by Prctuid, PCode order by PCode)
from yourTable
) x
where x.RN <= 10