私はすでにこれについてGoogleで検索しましたが、私の問題の正しい解決策を得ることができません。ここでwhere句グループによるSQLクエリ
私が欲しいのは、where句の各フィールドで結果を得ることです。彼らは別の年の値を持っているIN (intYear,intYear1,intYear2,intYear3,intYear4)
の中にあった
WHERE
(
act.REFERENCENO IS NOT NULL
AND act.CUSTOMER LIKE theCustomer
AND act.SALESTYPE LIKE theSalesType
AND(
YEAR(act.ATDATE) IN(
intYear,
intYear1,
intYear2,
intYear3,
intYear4
)
)
);
その1:あなたは、コードを見ることができる場合
BEGIN
-- INSERT INTO tmp_sr_accountsales (REFERENCENO, CUSTOMER, TransDate, SALESTYPE, STDTERMS, Amount)
SELECT act.referenceno,
act.customer,
act.atdate transdate,
act.salestype,
cust.stdterms,
Ifnull(act.totalamount, 0)- Ifnull(act.discountamnt, 0) AS amount,
Ifnull(act.totalamount, 0)- Ifnull(act.discountamnt, 0) AS amount2,
Ifnull(act.totalamount, 0)- Ifnull(act.discountamnt, 0) AS amount3,
Ifnull(act.totalamount, 0)- Ifnull(act.discountamnt, 0) AS amount4,
Ifnull(act.totalamount, 0)- Ifnull(act.discountamnt, 0) AS amount5,
intyear AS intyear,
intyear1 AS intyear2,
intyear2 AS intyear3,
intyear3 AS intyear4,
intyear4 AS intyear5
FROM 100 _actual_transaction act
INNER JOIN 000 _customer cust
ON (
act.customer = cust.customername)
WHERE (
act.referenceno IS NOT NULL
AND act.customer LIKE thecustomer
AND act.salestype LIKE thesalestype
AND (
year(act.atdate) IN(intyear,
intyear1,
intyear2,
intyear3,
intyear4)));
END;
:ここに私のコードです。私はそれぞれの結果を得たいと思っています。結果を1ずつ得ることは可能ですか?そのコードの結果は、そのクエリで選択されたすべてのデータを追加するだけであるためです。
タグDBMSあなたに「年の値ごとに」取得するために、これらの行の上にGROUP BYおよびSUM()を使用することができます再使用します。 (一部の製品固有の関数が使用されています) – jarlh
コードの書式設定を改善してください。私が読むために横にスクロールしなければならない場合、私はただ残します。 – jarlh
これはSQL Serverではありません。 'IFNULL'関数はそこに存在しません。 –