求和(c1)*求和(c2)和求和(c1*c2)之间的SQL不同
在SQL语言中,两者的结果或性能有什么不同求和(c1)*求和(c2)和求和(c1*c2)之间的SQL不同,sql,Sql,在SQL语言中,两者的结果或性能有什么不同 sum(c1) * sum(c2) from t 及 我用它来计算销售总额 select sum(price * quantity) as total from Bill 那么最好的选择是什么呢?空值和零值是一个问题 Declare @YourTable table (C1 money,C2 money) Insert Into @YourTable values (100,10) ,(100,null) Select sum(c1) * su
sum(c1) * sum(c2) from t
及
我用它来计算销售总额
select sum(price * quantity) as total from Bill
那么最好的选择是什么呢?空值和零值是一个问题
Declare @YourTable table (C1 money,C2 money)
Insert Into @YourTable values
(100,10)
,(100,null)
Select sum(c1) * sum(c2) -- 2000.00
From @YourTable
Select sum(c1 * c2) -- 1000.00
From @YourTable
空值和零是一个问题
Declare @YourTable table (C1 money,C2 money)
Insert Into @YourTable values
(100,10)
,(100,null)
Select sum(c1) * sum(c2) -- 2000.00
From @YourTable
Select sum(c1 * c2) -- 1000.00
From @YourTable
垂直和水平总和。。。假设没有空值
declare @mytable table (a int, b int)
insert into @mytable
values
(1,1),
(2,3)
select * from @mytable
select sum(a) * sum(b) from @mytable -- result is 12 .. vertical/column, summarize column first then multiply to other column
select sum(a*b) from @mytable --- result is 7 .. horizontal/row, summarize the product of a and b
垂直和水平总和。。。假设没有空值
declare @mytable table (a int, b int)
insert into @mytable
values
(1,1),
(2,3)
select * from @mytable
select sum(a) * sum(b) from @mytable -- result is 12 .. vertical/column, summarize column first then multiply to other column
select sum(a*b) from @mytable --- result is 7 .. horizontal/row, summarize the product of a and b
这不是SQL的问题。这只是基础数学。假设c1=(0,1)和c2=(2,3)。然后: 与以下内容不相同:
sum(c1*c2) alias... (0*2)+(1*3) = 3
这不是SQL的问题。这只是基础数学。假设c1=(0,1)和c2=(2,3)。然后: 与以下内容不相同:
sum(c1*c2) alias... (0*2)+(1*3) = 3
你会得到不同的结果吗?请不要对每个数据库平台进行垃圾标记。垂直和水平总和数据中是否有零?这些值是浮点值还是数字值?这两种情况中的任何一种都可能导致差异。c1*c2逐行出现,总和(c1)出现在整列中。是否得到不同的结果?请不要对每个数据库平台进行垃圾标记。垂直与水平总和数据中是否有零?这些值是浮点值还是数字值?这两种情况中的任何一种都可能导致差异。c1*c2逐行出现,总和(c1)出现在整列中我使用它来合计销售总额``从清单中选择总和(价格*数量)作为总额``那么最好的选择是什么?每行计算是您选择的价格*数量``我使用它来合计销售总额``选择总和(价格*数量)作为账单`'的总计,那么最好的选择是什么呢?每行计算是您选择的价格*数量