私は2つのテーブルを持っています:
AppDetailFee table has AppID (PK), TypeID, Amount
AppDetail table has AppID (PK)
AppID で両方のテーブルを結合し、次の TypeID と金額を確認する必要があります。3 つのシナリオがあります。
If TypeID = 6 and Amount = 0 then print appid and amount zero
If typeID = 6 and amount <> 0 - bypass and do not print
When TypeID <> 6 then print zero
以下は私が使用したコードです。ところで、ゼロに等しくないすべての行の結果がゼロの量で得られます。
どんな助けでも大歓迎です。ありがとう
SELECT ad.AppID
, MAX(case when (adf.TypeID = 6 AND adf.Amount = 0) then 0
when (adf.TypeID = 6 AND adf.Amount <> 0) then Adf.Amount
ELSE 0 END) AS FeeAmount
FROM
AppDetail AS ad
inner join AppDetailFee adf ON
ad.AppID = adf.AppID
WHERE adf.Amount =0