2011-07-06 8 views
2

初期テーブル:その列の3列目との和のことでグループの後特定のグループ

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 

答えて

5
SELECT Col1, Col2, SUM(Col3) 
FROM dbo.YourTable 
GROUP BY Col1, Col2 

そのような何か ?

4

すべての列の値が同じである場合、それになるだけのグループでグループに複数の列を指定します。

SELECT ColA, ColB, Sum(ColC) as Summation 
FROM YourTable 
GROUP BY ColA, ColB 
0
 
    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; 
+0

はので、私の答えは間違っていたとは、rootを理解していませんでしたか?または、MS SQLとは異なる作業でグループ化しますか? –

+0

no..itsはms sqlで正常に動作します。この答えに誰が投票したか分かりません。 –

関連する問題