I have problem with my SQL query
I have
T1:
ID STATUS REPORTEDBY
1 CLOSED USER1
2 CLOSED USER2
3 NEW USER1
4 INPRG USER1
5 CLOSED USER1
T2:
T1ID STATUS
1 NEW
1 CHECKING
1 CLOSED
2 NEW
2 CHECKING
2 CLOSED
3 NEW
4 CHECKING
4 INPRG
5 INPRG
5 CLOSED
As result I want to get this:
USER NumberHasCHECKING NumberDifferentFromNewChecking NumberClosed
USER1 2 3 2
USER2 1 1 1
I want to get as result group by REPORTEDBY field
-
number of records from T1 for which exist CHECKING status in T2,
-
number of records from T1 which is now in status differentg from NEW or CHECKING in T1
-
and number of records in T1 which is currently in CLOSED status in T1.
.
select reportedby,count (case when T2.status='CHECKING' then 1 end) as NumberHasChecking,
count (case when T2.status not in ('NEW','CHECKING') then 1 end) as NumberDifferentFromNewChecking,
count (case when T1.status='CLOSED' then 1 end) as NumberClosed
from t1
inner join t2 on T1.ID=T2.T1ID
group by reportedby
but after I do inner join I am getting much greater result for second and third column.
How to solve this?
thank you
Not sure if this will work on DB2: