我需要从2个表中获取记录 procedure和procedure_user_map,我在sql服务器上编写一个查询 以便根据所选的限制和偏移量获取记录 从ui,我正在编写以下查询以获取记录
但是我没有得到10条记录,rownum()函数不起作用 在找到不同之后,它会将计数放在每一行
WITH MD_Results AS
(
SELECT P.pk, P.procedure_name,
RowNum() OVER (order by P.procedure_name asc) AS RowNum
FROM "procedure" P, "procedure_user_map" PUM
where P.pk = PUM.procedure_fk
)
SELECT DISTINCT "pk", "procedure_name", RowNum FROM MD_Results
WHERE RowNum > 0 AND RowNum <= 0 + 10
我希望获得不同的过程记录并对其执行rownum() 得到正确的计数
答案 0 :(得分:0)
尝试这样的事情
WITH MD_Results AS
(
SELECT P.pk, P.procedure_name,
RowNum() OVER (PARTITION BY P.procedure_name order by P.procedure_name asc) AS RowNum
FROM "procedure" P, "procedure_user_map" PUM
where P.pk = PUM.procedure_fk
)
SELECT top 10 pk, procedure_name, RowNum FROM MD_Results
WHERE RowNum > 1