in Databases
1,805 views
3 votes
3 votes

Consider the set of relations

  • EMP (Employee-no. Dept-no, Employee-name, Salary)
  • DEPT (Dept-no. Dept-name, Location)

Write an SQL query to:

Calculate, for each department number, the number of employees with a salary greater than Rs. 1,00,000

in Databases
1.8k views

3 Answers

5 votes
5 votes
SELECT Dept-no, count(Employee-no) as total_employees
FROM EMP
WHERE Salary > 100000
GROUP BY Dept-no

2 Comments

i am getting something like this! 

SELECT COUNT(EMPLOYEE-NO),DEPT-NO FROM EMP e,DEPT d WHERE 
e.dept-no=d.dept-no HAVING SALARY > 100000  GROUP BY (DEPT-NO);

 

pls check it once!

0
0

@Pranavpurkar 

Having Clause can not come before Group By clause.

0
0
2 votes
2 votes
select Dept-no, count(*)

from EMP group by Dept-no having salary > 100000

1 comment

I am also thinking the same.

I think we Can also use having in group by
0
0
0 votes
0 votes
select Dept-no, count(Employee-no)

from EMP where Salary>100000 group by Dept-no

Related questions