Subject | Re: Select returns too many columns |
---|---|
Author | mikcaau |
Post date | 2007-03-19T10:56:12Z |
> The solution to the problem you asked about, is to 'sum the case'rather
> than 'case the sum' ;o)Svein,
>
> select mas.CUSTID,
> Cust.CUST_NAME as Cust_Sup,
> count(mas.ID),
> sum(
> case
> when mas.DIRECTION = 'CREDIT' then mas.ENTRY_TOTAL
> else 0
> end) as Credit,
> sum(
> case
> when mas.DIRECTION = 'DEBIT' then mas.ENTRY_TOTAL
> else 0
> end) as Debit
> from TRANS89 mas
> left join MACT_CUST_SUP_LIST Cust
> on Cust.CUSTID = mas.CUSTID
> and Cust.CUSTID in ('7', '8', '9')
> group by 1, 2
>
> HTH,
> Set
>
Thank you for the answer and the guidance. I will get my head back
into joins and this time I will really learn them, true
Mick