我想编写一个查询来从同一个表中检索COUNT(of employees with the salary=1000)
和COUNT(of total no of employees)
。
任何想法??
答案 0 :(得分:5)
另一种方法:
SELECT
COUNT(*) AS total_employees,
SUM(CASE WHEN salary = 1000 THEN 1 ELSE 0 END) AS employees_with_1000_salary
FROM
Employees
答案 1 :(得分:3)
SELECT COUNT(EmployeeID) as 'Total Employees',
(SELECT COUNT(EmployeeID) FROM Employees WHERE Salary = 1000) as 'Salaried'
FROM Employees
答案 2 :(得分:2)
select
count(*) totalCount,
count(case when salary = 1000 then 1 else NULL end) specialCount
from Employees
COUNT计算非空行。
答案 3 :(得分:0)
select count(*) as employeeCount,
(select count(*) from employee where salary=1000) as bigmoneyEmployeeCount
from employee