计数问题()

时间:2010-07-08 19:24:22

标签: sql-server sql-server-2005

我想编写一个查询来从同一个表中检索COUNT(of employees with the salary=1000)COUNT(of total no of employees)。 任何想法??

4 个答案:

答案 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