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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -