select * from 
(
select id,class,
sum(pay_money) as pay_money,
row_number() over(order by id) as rownum 
from table_class
group by id,class
) as temp  
where rownum between 1 and 3 order by id,class这样是可以实现分页可是每次得到的数据是不一样的.我想在内部排序,可是是MS-SQL不让...
求高手指教!

解决方案 »

  1.   

    select * from 
    (
    select *,row_number() over(order by id) as rownum  from 
    (
    select id,class,sum(pay_money) as pay_money
    from table_class
    group by id,class
    ) a  
    )b
    where rownum between 1 and 3 order by id,class
      

  2.   


    select * from 
    (
        select *,row_number() over(order by id,class) as rownum  from 
        (
            select id,class,sum(pay_money) as pay_money
            from table_class
            group by id,class
        ) a  
    )b
    where rownum between 1 and 3
      

  3.   

    谢谢楼上!我试了一个.问题解决了.把ORDER BY 后面加上ID,CLASS就行了.因为之后我只加了ID,所以结果只按ID排序了.