I have table like below
+---------+-----------+---------+-------------+--------+
| call_id | seg_order | src_dn | dst_dn_type | dst_dn |
+---------+-----------+---------+-------------+--------+
| 29192 | 1 | "8004" | 0 | "2215" |
| 29193 | 1 | "8000" | 6 | "2239" |
| 29194 | 1 | "10001" | 6 | "8802" |
| 29194 | 2 | "10001" | 6 | "8802" |
| 29194 | 3 | "10001" | 4 | "8003" |
| 29194 | 4 | "10001" | 4 | "8003" |
| 29194 | 5 | "8003" | 0 | "2225" |
| 29194 | 6 | "8003" | 0 | "2225" |
| 29194 | 7 | "10001" | 0 | "2225" |
| 29195 | 1 | "10000" | 6 | "8857" |
| 29195 | 2 | "10000" | 6 | "8857" |
| 29195 | 3 | "10000" | 4 | "8002" |
| 29195 | 4 | "10000" | 4 | "8002" |
| 29195 | 5 | "8002" | 0 | "2213" |
| 29195 | 6 | "8002" | 0 | "2213" |
| 29195 | 7 | "10000" | 0 | "2213" |
| 29196 | 1 | "10002" | 6 | "8800" |
| 29196 | 2 | "10002" | 6 | "8800" |
| 29196 | 3 | "10002" | 4 | "8000" |
| 29196 | 4 | "10002" | 4 | "8000" |
| 29196 | 5 | "8000" | 0 | "2240" |
| 29196 | 6 | "8000" | 0 | "2240" |
| 29196 | 7 | "10002" | 0 | "2240" |
| 29197 | 1 | "10003" | 6 | "8804" |
| 29198 | 1 | "8000" | 0 | "2240" |
| 29199 | 1 | "8004" | 0 | "2220" |
| 29200 | 1 | "8004" | 0 | "2213" |
| 29201 | 1 | "10002" | 6 | "8800" |
| 29202 | 1 | "10003" | 6 | "8804" |
| 29202 | 2 | "10003" | 6 | "8804" |
| 29202 | 3 | "10003" | 2 | "8010" |
| 29202 | 4 | "10003" | 4 | "8004" |
| 29202 | 5 | "10003" | 4 | "8004" |
| 29202 | 6 | "8004" | 0 | "2215" |
| 29202 | 7 | "8004" | 0 | "2215" |
| 29202 | 8 | "10003" | 0 | "2215" |
+---------+-----------+---------+-------------+--------+
as a result, I need 3 column that contains;
- how many "call_id" group has "10001" in "src_dn" column
- how many "call_id" group has "10001" in "dst_dn" column
- how many "call_id" group has "6" in "dst_dn_type" when "seg_order" is max (on last segment)
for first and second, "10001" should be count one per group.
Thanks
edit: expected result
+---------+-----------+---------+
| inbound | outbound | ivr |
+---------+-----------+---------+
| 1 | 0 | 1 |
+---------+-----------+---------+
edit: what I've done so far
this query works (I believe) for first and second steps
select * from
(select count(distinct call_id) from tbl where src_dn='10001') as t1,
(select count(distinct call_id) from tbl where dst_dn='10001') as t2