sql - Get separate count for each condition within group -
i trying view of table information , oracle 10g table lists counts of specific values of column in own columns each row being group value.
for example: first select :
select processed_by, count(priority) p2 agreement_activity priority = '2' group processed_by which outputs:
processed_by p2 ------------------------------ ---------- alicia 2 christine 2 the second select is:
select processed_by, count(priority) p1 agreement_activity priority = '1' group processed_by which outputs:
processed_by p1 ------------------------------ ---------- bonita 2 alicia 6 christine 2 what looking output values following:
processed_by p1 p2 ------------------------------ ---------- ---------- bonita 2 alicia 6 2 christine 2 2 is possible?
you can use sum case expression conditional count:
select processed_by , sum(case when priority = 1 1 else 0 end) p1 , sum(case when priority = 2 1 else 0 end) p2 agreement_activity group processed_by p.s. if don't care p1 or p2 maybe null instead of 0 can omit else in both expressions.
Comments
Post a Comment