降序排序不起作用

时间:2013-12-27 08:27:33

标签: sql sql-server stored-procedures

此存储过程不执行数据的降序我不知道为什么!

BEGIN 
    SET nocount ON; 

    WITH ordereddata 
         AS (SELECT *, 
                    rn = Row_number() 
                           OVER ( 
                             ORDER BY articleid ) 
             FROM   articles) 
    SELECT * 
    FROM   ordereddata 
    WHERE  rn <= @UpperBound 
           AND rn >= @LowerBound 
    ORDER  BY articleid DESC 
END 

这是我给@Upperbound和@LowerBound值

时的结果
  

aricleid 54 55 56 57。 。

2 个答案:

答案 0 :(得分:1)

试试这个

BEGIN
SET NOCOUNT ON;
WITH OrderedData
as (
  select * , rn = ROW_NUMBER() OVER (ORDER BY articleid desc )  FROM articles
   )

select * from OrderedData
where rn <= @UpperBound AND rn >= @LowerBound 
ORDER BY articleid desc
END

答案 1 :(得分:1)

试试这个

BEGIN
  SET NOCOUNT ON;
WITH OrderedData
as (
  select * , rn = ROW_NUMBER() OVER (ORDER BY articleid)  FROM articles 
  )

select * from OrderedData
where rn <= @UpperBound AND rn >= @LowerBound 
ORDER BY articleid desc
END