通过一个语句,只让其中的前三个月求和,表如下:
YEAR  MONTH  TOTAL
2008     1      1000
2008     2      1000
2008     3      2000
2008     4      2000
2008     5      3000
2008     6      3000
谢谢

解决方案 »

  1.   

    select sum(total) from (
    select *,rn=row_number()over(order by month) from tb
    ) where rn<=3
      

  2.   


    select sum(total) from
    (select top 3 * from 表 order by month)a
      

  3.   

    select sum(total) from (
    select *,rn=row_number()over(order by month) from tb
    ) t where rn<=3
    select sum(total) from (
    top 3 * from tb
    ) t 
      

  4.   


    select sum(total) from tb where month <= 3???
      

  5.   

    select sum(total) from (
    select *,rn=row_number()over(order by month) from tb
    ) where rn<=3