select sum(A+B) as AB,sum(A+B+C) from db 这句能不能换成
select sum(A+B) as AB,sum(AB+C) from db  请帮帮忙,我这样执行不对找不到AB

解决方案 »

  1.   

    declare @t table(rq varchar(10) , a int , b int ,c int)
    insert @t 
    select '2006-01' , 20000 ,1,2 union all
    select '2006-02' , 30000 ,2,3 union all
    select '2006-03' , 50000 ,4,5select sum(a+b) , sum(a+b+c) from @t----------- ----------- 
    100007      100017(所影响的行数为 1 行)
      

  2.   

    没发现问题.除非,你A,B,C三个字段不是数值型的.
      

  3.   

    select sum(A+B) as AB,sum(AB+C) from db  请帮帮忙,我这样执行不对找不到AB-----------
    这不行的!
    AB是sum(A+B)这个虚字段,不能在同一个查询过程中使用的
      

  4.   

    select sum(A+B) as AB,sum(AB+C) from db  请帮帮忙,我这样执行不对找不到AB
    -----------------------------------------------------------------------------
    不用能别名+C