sql - get All distinct (by ID) Users list and count only thoose who is Active -
i need distinct user list , count thoose active , like
id | count | active 1 | 0 | false 2 | 1 | true 3 | 6 | true
but when do
select id,count(*) users active='true' group id
i got distinct active
id | count | active 2 | 1 | true 3 | 6 | true
how write query want?
you need move condition aggregate:
select id, sum(case when active='true' 1 else 0 end) users group id
Comments
Post a Comment