1 1 3
1 1 4
1 2 1
1 2 3
2 1 5
2 1 2
2 2 2
2 2 3
組後
通過在第三列和總和在該柱:
1 1 7
1 2 4
2 1 7
2 2 5
1 1 3
1 1 4
1 2 1
1 2 3
2 1 5
2 1 2
2 2 2
2 2 3
組後
通過在第三列和總和在該柱:
1 1 7
1 2 4
2 1 7
2 2 5
SELECT Col1, Col2, SUM(Col3)
FROM dbo.YourTable
GROUP BY Col1, Col2
東西 那樣??
指定多個列由組,它只會當組中的所有列中的值是相同的:
SELECT ColA, ColB, Sum(ColC) as Summation
FROM YourTable
GROUP BY ColA, ColB
select one , two, sum(three) from ( select 1 as one, 1 as two, 3 as three from dual union select 1 as one, 1 as two, 4 as three from dual union select 1 as one, 2 as two, 1 as three from dual union select 1 as one, 2 as two, 3 as three from dual union select 2 as one, 1 as two, 5 as three from dual union select 2 as one, 1 as two, 2 as three from dual union select 2 as one, 2 as two, 2 as three from dual union select 2 as one, 2 as two, 3 as three from dual ) group by one, two;
所以是我的答案錯了,你不明白的根源在哪裏?或者按MS SQL中不同的作品分組? –
沒有..在ms sql中正常工作。不知道是誰投下了這個答案。 –