Thomas
Thomas

Reputation: 6690

SQL Count Number of "Employees" With "Salary"

I've got a query that I'd like to write. The content of which is similar to what I am posting below:

SELECT id, name, position, salary, 
    (SELECT COUNT(salary 's') FROM employees WHERE s = salary) As NumberofEmployeesWithSalary
FROM employees
WHERE hire_date BETWEEN '2013-01-01' AND '2014-12-31'

Essentially, what I am after is the ability to sum the number of employees with a particular, dynamically-defined salary (so that I am able to form a percentage off it). I've wracked my brain on Google, dev.MySQL, and SO trying to find an answer.

I don't know if this is possible. I may just need to separate out each "salary type" into a separate COUNT query.

So, for instance, if my data contains:

Salary
------
30000
30000
30000
40000
40000
50000

I'd like to get back 3 for 30000, 2 for 40000, etc., specifically with the intent of using that result for a value in another query to grab a percentage.

Upvotes: 0

Views: 6764

Answers (2)

BM PRADEEP
BM PRADEEP

Reputation: 1

SELECT COUNT(2.02.) FROM employees WHERE salary != ( SELECT salary FROM employees WHERE MONTH(end_date) = MONTH(CURRENT_DATE()) AND YEAR(end_date) = YEAR(CURRENT_DATE()) ) AND end_date > CURRENT_DATE()

Upvotes: 0

mysqlrockstar
mysqlrockstar

Reputation: 2612

SELECT salary, count(*)  As NumberofEmployeesWithSalary FROM employees
WHERE hire_date BETWEEN '2013-01-01' AND '2014-12-31'
GROUP BY salary;

Try the above query and you should get something like this

Salary  NumberofEmployeesWithSalary
------  --------------------------
30000              3
40000              2
50000              1

Upvotes: 2

Related Questions