如何在SQL中SUM一个AS列

时间:2014-09-03 21:57:09

标签: sql sql-server

我有以下代码......

SELECT WF.Word, WF.Frequency, WW.Weight, (WF.Frequency * WW.Weight) AS Product
FROM WF 
INNER JOIN WW ON WW.Word = WF.word

其中输出以下内容......

WORD        | FREQUENCY | WEIGHT | PRODUCT
Fat           3           2        6
Ugly          2           4        8
Stupid        1           7        7

我还想同时对产品列求和。我理解如何对现有列求和,但不确定如何对我正在创建的列进行求和。

2 个答案:

答案 0 :(得分:0)

SELECT SUM(WF.Frequency * WW.Weight) AS Product
FROM WF 
INNER JOIN WW ON WW.Word = WF.word

答案 1 :(得分:0)

SELECT WF.Word, SUM(WF.Frequency) Frequency, SUM(WW.Weight) Weight, SUM(WF.Frequency * WW.Weight) AS Product
FROM WF 
INNER JOIN WW ON WW.Word = WF.word
GROUP BY WF.Word
;
SELECT SUM(WF.Frequency * WW.Weight) Product
FROM WF 
INNER JOIN 
WW ON WW.Word = WF.word