Reputation: 12709
I wants to write a query to retrieve COUNT(of employees with the salary=1000)
and COUNT(of total no of employees)
from the same table.
any ideas??
Upvotes: 2
Views: 194
Reputation:
select
count(*) totalCount,
count(case when salary = 1000 then 1 else NULL end) specialCount
from Employees
COUNT counts non-null rows.
Upvotes: 2
Reputation: 47402
Another method:
SELECT
COUNT(*) AS total_employees,
SUM(CASE WHEN salary = 1000 THEN 1 ELSE 0 END) AS employees_with_1000_salary
FROM
Employees
Upvotes: 5
Reputation: 9759
select count(*) as employeeCount,
(select count(*) from employee where salary=1000) as bigmoneyEmployeeCount
from employee
Upvotes: 0
Reputation: 1718
SELECT COUNT(EmployeeID) as 'Total Employees',
(SELECT COUNT(EmployeeID) FROM Employees WHERE Salary = 1000) as 'Salaried'
FROM Employees
Upvotes: 3