使用第二個case語句:
select name, (sum(case when TransTypeName like 'credit%' then (case when amount>0 then amount else 0 end;) else 0 end) -
sum(case when TransTypeName like 'Debit%' then (case when amount>0 then amount else 0 end;) else 0 end)) *5/100 as Interest
from ...........
,如果你不什麼返回了一加一是負面的:
select name, (case when (sum(case when TransTypeName like 'credit%' then amount else 0 end) -
sum(case when TransTypeName like 'Debit%' then amount) else 0 end)) *5/100)<0 then 0 else (sum(case when TransTypeName like 'credit%' then amount else 0 end) -
sum(case when TransTypeName like 'Debit%' then amount) else 0 end)) *5/100) as Interest
from ...........
呃,負值爲負....借方(貸方)爲什麼會是零? –
嗨米奇,我明白你的問題,但這是我的要求任務。 –
任何有這種荒謬要求的東西一定是功課。 –