myTable
3列のテーブルがあります。col_1
はINTEGER
で、他の 2 つの列はDOUBLE
です。たとえば、col_1={1, 2}, col_2={0.1, 0.2, 0.3}
. の各要素col_1
は のすべての値で構成され、 のcol_2
各要素のcol_2
値が繰り返されますcol_1
。3 番目の列には、以下に示すように任意の値を指定できます。
col_1 | col_2 | Value
----------------------
1 | 0.1 | 1.0
1 | 0.2 | 2.0
1 | 0.2 | 3.0
1 | 0.3 | 4.0
1 | 0.3 | 5.0
2 | 0.1 | 6.0
2 | 0.1 | 7.0
2 | 0.1 | 8.0
2 | 0.2 | 9.0
2 | 0.3 | 10.0
私が望むのはSUM()
、Value
列パーティションで集計関数を使用し、によってcol_1
グループ化することcol_2
です。上の表は次のようになります。
col_1 | col_2 | sum_value
----------------------
1 | 0.1 | 1.0
1 | 0.2 | 5.0
1 | 0.3 | 9.0
2 | 0.1 | 21.0
2 | 0.2 | 9.0
2 | 0.3 | 10.0
次のSQLクエリを試しました:
SELECT col_1, col_2, sum(Value) over(partition by col_1) as sum_value
from myTable
GROUP BY col_1, col_2
しかし、DB2 v10.5 では、次のエラーが発生しました。
SQL0119N An expression starting with "Value" specified in a SELECT
clause, HAVING clause, or ORDER BY clause is not specified in the
GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER
BY clause with a column function and no GROUP BY clause is specified.
何が間違っているかを親切に指摘できますか。私はSQLの経験があまりありません。
ありがとうございました。