在sql中多列的乘法。 [英] Multiplication of multiple columns in a sql.
问题描述
大家好我在sql中有10个不同的行和10个不同的列。对于每一行,有一个称为数量的公共列。现在我必须将每列中剩余行数的不存在乘以。我怎么能做到这一点?样品表如下所示。
sno数量a1 b1 c1 d1
1 5 4 10 11 9
2 4 2 8 10 7
3 6 2 3 1 9
所以我的输出应该是:
sno数量a1 b1 c1 d1
1 5 20 50 55 45
2 4 8 32 40 28
3 6 12 18 06 45
Hi all i have 10 different rows and 10 different columns in sql. for each row there is one common column called quantity. now i have to multiply the no present in the quantity for the rest of the rows for each and every column. how can i accomplish this? sample table is shown below.
sno quantity a1 b1 c1 d1
1 5 4 10 11 9
2 4 2 8 10 7
3 6 2 3 1 9
so my output should be:
sno quantity a1 b1 c1 d1
1 5 20 50 55 45
2 4 8 32 40 28
3 6 12 18 06 45
推荐答案
试试这个代码
Try this code
Create table #temp
(Id int identity(1,1),
quantity int,
a1 int,
b1 int,
c1 int,
d1 int
)
insert into #temp Values (5,4,10,11,9),(4,2,8,11,9),(6,3,10,1,9)
SELECT Id, quantity,(a1*quantity) as A1,(b1*quantity) as B1,(c1*quantity) as C1,
(d1*quantity) as D1 from #temp
DROP table #temp
这篇关于在sql中多列的乘法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!