0

我需要从 2 个表 procedure 和 procedure_user_map 中获取记录,我正在 sql sever 中编写一个查询,以便根据从 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() 以使计数正确

4

1 回答 1

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
于 2013-08-26T03:46:14.537 回答