Create table aa (id int,quantity int, price int)insert aa select 1,2,10 union all select 1,5,20 union all select 1,1,15 select [总金额]=sum(quantity*price) from aa (所影响的行数为 1 行) 总金额 135
最好这样写: select [总金额]=sum(isnull(quantity,0)*isnull(price,0)) from A 这样是考虑字段有为null 的情况。 如过里面存在null的情况,就算的结果就是null值。
select 1,2,10 union all
select 1,5,20 union all
select 1,1,15 select [总金额]=sum(quantity*price) from aa
(所影响的行数为 1 行)
总金额
135
select [总金额]=sum(isnull(quantity,0)*isnull(price,0)) from A
这样是考虑字段有为null 的情况。
如过里面存在null的情况,就算的结果就是null值。