2014-12-31 79 views
-1
Linetotal tax taxsum 
-------------------- 
1150  Bed 250 
1150  HSC 150 
1150  CESS 110 

我想總的taxsum(250 + 150 + 110)和linetotal(1150)的總和= 1660薩姆多列的

這能在SQL Server使用T完成-SQL查詢?

+3

是............................. –

+0

您的問題有點不清楚。你可以添加你想要獲取這個樣本數據的輸出嗎? – Mureinik

+0

我究竟需要什麼(1150 + 250 + 150 + 110)。 –

回答

0
Select sum(taxsum) + avg(linetotal) 
From yourtable 
+0

很好.... thanx夥計:) –

+0

如果您發現此答案有幫助,請繼續並上傳它,並通過單擊答案旁邊的複選標記將其標記爲接受的答案。 –

+0

thanq這麼多爲您的解決方案,其工作! –

0

這是語法,你想用

SELECT SUM(column_name) FROM table_name; 

您的代碼可以作爲(假設你的表名是GetTheSum

SELECT SUM(taxsum) AS TAXTOTAL FROM GetTheSum; 

最終的答案:

SELECT (Linetotal + taxsum) AS TOTAL FROM GetTheSum 
+0

從這我怎麼能得到這個值=(1150 + 250 + 150 + 110 = 1660)? –

+0

嘗試這些步驟.... – SanyTiger

+0

最後一個查詢不會返回OP詢問的值。它會返回:(1150 + 1150 + 1150)+(250 + 150 + 110)= 3.960 – mordack550

0

Try:

SELECT SUM(taxsum) AS Taxes, SUM(LineTotal) + SUM(taxsum) AS Total 
FROM mytable 
GROUP BY LineTotal 
0

你可以用子查詢來做到這一點。

SELECT Linetotal + s FROM (
    SELECT Linetotal, sum(taxsum) s FROM table_name GROUP BY Linetotal 
) a 

或者只是

SELECT Linetotal + sum(taxsum) AS total FROM table_name GROUP BY Linetotal 

注:問題是有點不清楚。我假設你想爲每個Linetotal總計taxsum,並將Linetotal添加一次。