select customername name,product,money from customer
union all
select '总计','',sum(money) from customer

解决方案 »

  1.   

    select a.customername as name ,a.product,a.money,b.money as sum_money 
    from customer a
    left join (select sum(money) money from customer) b
    on 1=1
      

  2.   

    declare @i as decimal(18,2)select @i = money from customer compute sum(money) select @i
      

  3.   


    select name,volume from tt union all
    select '总计',sum(volume) from tt
    --赋值变量
    declare @i decimal
    select @i=sum(volume) from tt
    print @i
      

  4.   

    declare
    @i int
    select customername,product,money from customer
    union
    select @i=sum(money)from customer
      

  5.   

    上面的高手人人有分。另请 dawugui(潇洒老乌龟) 注意:
    参考了你的方法,如果把存储过程写成下面的形式是否可以? 
    CREATE PROCEDURE aaa @yyy decimal(18,2) outputASselect customername, product, @yyy = money from customer compute sum(money) by customer where customername='someone'
      

  6.   

    如果想把兩個結果放到一個查詢裡,這麼寫select customername as name,product,SUM(money) As money from customer Group By customername,product With Rollup Having customername Is Null Or product Is Not Null
      

  7.   

    Create Table customer
    (customername Varchar(10),
     product Varchar(10),
     [money] Money)
    Insert customer Select 'A', 'A1', 200
    Union All Select 'A', 'A2', 300
    Union All Select 'B', 'B1', 200
    GO
    select customername as name,product,SUM(money) As money from customer Group By customername,product With Rollup Having customername Is Null Or product Is Not Null
    GO
    Drop Table customer
    --Result
    /*
    name product money
    A A1 200.0000
    A A2 300.0000
    B B1 200.0000
    NULL NULL 700.0000
    */