-4

MYSQL:

SELECT * FROM book ORDER BY $sidx $sord LIMIT $start , $limit;

我如何把它变成甲骨文?

4

4 回答 4

3

您必须使用rownum属性,但您必须将其应用于已经排序的结果集,并且您需要从内部查询中传递它(感谢 Bob Jarvis 和 Daniel Hilgarth:请查看他们的解释和评论中给出的链接)。它应该是这样的:

SELECT * FROM
(SELECT b.*, rownum as row_num FROM book b ORDER by $sidx $sord)
WHERE row_num BETWEEN $start AND $start + $limit;
于 2012-09-18T10:52:32.840 回答
1

我不熟悉 oracle 语法,但您可以使用该ROW_NUMBER()函数对行进行排名,然后选择具有以下内容的行rank BETWEEN @start and @limit

   SELECT *
   FROM 
   (
       select *,
           ROW_NUMBER() OVER (ORDER BY ID DESC) AS rank
       FROM book
   )
   WHERE rank BETWEEN @start AND @end
   /* OR
   WHERE BETWEEN ((@PageNum - 1) * @PageSize + 1)
     AND (@PageNum * @PageSize)
   /*
于 2012-09-18T10:53:07.313 回答
1
select * from(
select rownum as row_num, id from t
  )
where row_num between :start and :start+:limit
于 2012-09-18T10:57:03.397 回答
0

10g 起

WITH CTE AS(SELECT  b.*, Row_Number() OVER(ORDER BY SIDX,SORD) AS Rn FROM BOOK b)
SELECT *
FROM CTE
WHERE Rn BETWEEN STARTLIMIT AND ENDLIMIT
于 2012-09-18T10:53:02.887 回答