chamara
chamara

Reputation: 12709

Problem With Count()

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

Answers (4)

ToxicAvenger
ToxicAvenger

Reputation:

select 
     count(*) totalCount, 
     count(case when salary = 1000 then 1 else NULL end) specialCount
from Employees

COUNT counts non-null rows.

Upvotes: 2

Tom H
Tom H

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

heisenberg
heisenberg

Reputation: 9759

select count(*) as employeeCount,
(select count(*) from employee where salary=1000) as bigmoneyEmployeeCount
from employee

Upvotes: 0

Nick
Nick

Reputation: 1718

    SELECT COUNT(EmployeeID) as 'Total Employees',   
    (SELECT COUNT(EmployeeID) FROM Employees WHERE Salary = 1000) as 'Salaried'
    FROM Employees 

Upvotes: 3

Related Questions