我有 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