根据列值乘以列的组合 [英] Multiply combination of columns based on a column value
本文介绍了根据列值乘以列的组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何根据一列中的值乘以列的值。
How to multiply values of the columns based on the value in one column.
示例
Col1 Col2 Col3 Col4
10 10 10 casea (multiply col1 * col2)
20 20 20 caseb (multiply col1 * col3)
30 30 30 casec (multiply col2 * col3)
查询如下:
select col1, col2, col3, col4, total
将返回
10,10,10,casea,100
20,20,20,caseb,400
30,30,30,casec,900
当然,性能始终是一个重要的问题。
Of course performance is an important issue as always.
感谢您的参与。
推荐答案
select
Col1,
Col2,
Col3,
Col4,
CASE Col4
WHEN 'casea' then col1*col2
WHEN 'caseb' then col1*col3
WHEN 'casec' then col2*col3
END AS Total
FROM YourTable
这篇关于根据列值乘以列的组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文