次のクエリがあります。
SELECT
tableOneId
SUM(a+b+c) AS tableOneData,
MIN(d) AS tableTwoData,
FROM
tableTwo JOIN tableOne ON tableOneId = tableTwoId
GROUP BY
tableOneId
上記の列はすべて として宣言されていnumeric(30,6) NOT NULLます。
にはtableOne、合計 (列a, b, c) が の列と等しいdエントリがありますTable Two。
これの簡単な例:
Table One (id here should read tableOneId to match above query)
id=1, a=1, b=0, c=0
id=1, a=0, b=2, c=0
id=2, a=1, b=0, c=0
Table Two (id here should read tableTwoId to match above query)
id=1, d=3
id=2, d=1
私の最初の反復は使用されSUM(d)/COUNT(*)ましたが、除算が面倒なので、現在使用していMIN(d)ます。このクエリを記述するより良い方法は何でしょうか?