Need Help! Trying to determine how can I return all rows and IF chargetypeid '19' exist ALSO display that value but no other chargetypes? Currently it's returning all '19' chargetypes and ALL '0' but if I put "= chargetypeid = '19' it only returns data that has that value in it.
Query:
select distinct
a.accountnum,
a.cycleid,
a.usagecharges,
a.totalcurrentcharges,
b.chargeamount,
case when b.chargeTypeId=19 then '19' else '0' END as chargeType
from
invoice.invoice a
left join invoice.invoice_charges b on b.invoiceid=a.invoiceid
where
a.cycleid IN ('388','398')
and
a.revenuestream = '50'
and
order by accountnum, chargeType desc, cycleid;