如何修改此查询以在startindex和endindex rownum之间使用

时间:2014-03-23 11:13:20

标签: database oracle between row-number rownum

如何修改此查询以便我在rownum 10和21之间获得结果,例如:

   SELECT DAL_ROWNOTABLE.DAL_ID
     FROM (SELECT ticket.id AS "DAL_ID" 
          FROM ticket_table ticket 
          WHERE (ticket.type = N'I' ) AND 
        (ticket.tenant IS NULL OR
         ticket.tenant IN (SELECT tgm.tenant_id 
                           FROM tenant_group_member tgm
                           WHERE tgm.tenant_group = HEXTORAW('30B0716FEB5F4E4BB82A7B7AA3A1A42C') 
                          ) 
        )
  ORDER BY ticket.id
 ) DAL_ROWNOTABLE 
  WHERE rownum <= 21;

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

rownum更改为row_number()

SELECT DAL_ROWNOTABLE.DAL_ID
FROM (SELECT ticket.id AS "DAL_ID",row_number() over (order by ticket_id) as seqnum
      FROM ticket_table ticket 
      WHERE (ticket.type = N'I' )AND
            (ticket.tenant IS NULL OR
            ticket.tenant IN(SELECT tgm.tenant_id 
                              FROM tenant_group_member tgm
                              WHERE tgm.tenant_group = HEXTORAW('30B0716FEB5F4E4BB82A7B7AA3A1A42C') 
                             ) 
        )
     ) DAL_ROWNOTABLE 
WHERE seqnum between 10 and 21;