sql - Database query for count -
i have 1 table with
id | name | dept 1 | | d-1 2 | b | d-1 3 | c | d-2 4 | d | d-3 5 | e | d-1 6 | f | d-3 7 | g | d-4
now want fetch result like
dept | count(dept) d-1 | 3 others | 4
can 1 me write query?
you need use case
group data d-1
, others
:
select case when dept = 'd-1' 'd-1' else 'others' end dept, count(*) total yt group case when dept = 'd-1' 'd-1' else 'others' end;
see sql fiddle demo
Comments
Post a Comment