Author: Shruti Takkar
Subject: Require help in DB2 Query
Posted: Wed Aug 03, 2016 10:57 pm (GMT 5.5)
Hi ,
I have to execute below problem in DB2 query, please suggest some valuable options.
Consider Table A having account details.
I need to count accounts from Table A for multiple scenarios.
I can count accounts using multiple case when conditions like below.
===========================================
select Count(case when t1.a = 1 then 1 else 0 end) as A_COUNT
, Count(case when t1.b = 2 then 1 else 0 end) as B_COUNT
from t1
============================================
My problem here is,, if my account is counted in A_COUNT, it should not get double counted in B_COUNT.
There are multiple when conditions and it is not possible to tweak them to make all conditions mutually exclusive.
Regards,
Shruti
Subject: Require help in DB2 Query
Posted: Wed Aug 03, 2016 10:57 pm (GMT 5.5)
Hi ,
I have to execute below problem in DB2 query, please suggest some valuable options.
Consider Table A having account details.
I need to count accounts from Table A for multiple scenarios.
I can count accounts using multiple case when conditions like below.
===========================================
select Count(case when t1.a = 1 then 1 else 0 end) as A_COUNT
, Count(case when t1.b = 2 then 1 else 0 end) as B_COUNT
from t1
============================================
My problem here is,, if my account is counted in A_COUNT, it should not get double counted in B_COUNT.
There are multiple when conditions and it is not possible to tweak them to make all conditions mutually exclusive.
Regards,
Shruti