Here i am using two count functions with different conditions in a single query.
select count(case when department_id = 10 and salary<5000 then 1 end),
count(case when department_id = 20 then 1 end)
from employees;
Output:
If we want the output as the two results in same column,
select count(EMPLOYEE_ID) from employees where DEPARTMENT_ID=30 and salary<5000
union all
select count(EMPLOYEE_ID) from EMPLOYEES where DEPARTMENT_ID=50;
Output:union all
select count(EMPLOYEE_ID) from EMPLOYEES where DEPARTMENT_ID=50;
References: http://stackoverflow.com/questions/12789396/how-to-get-multiple-counts-with-one-sql-query.
Nice one.Keep posting
ReplyDelete