-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHaving-Clause-OrderBY.sql
55 lines (41 loc) · 1.19 KB
/
Having-Clause-OrderBY.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
16.
-- Display number of employees in each department.
select
DEPARTMENT_ID,
count(EMPLOYEE_ID) as Number_of_Employees
from hr.employees
group by DEPARTMENT_ID;
17.
--Display number of employees who joined after 15th of month.
select
count(hire_date) as Number_of_Employers
from hr.employees
where extract(day from hire_date) <= 15;
18.
--Display job ID for jobs with average salary more than 10000.
select
JOB_ID,
avg(salary) as Avg_Salary
from hr.employees
group by JOB_ID
having avg(salary) > 10000;
19.
--Display average salary of employees in each department who have commission percentage.
select
DEPARTMENT_ID,
round(avg(salary),0) as Average_Salary
from hr.employees
where COMMISSION_PCT is not null
group by DEPARTMENT_ID;
20.
-- Display job ID, number of employees, sum of salary, and difference between the highest
-- salary and the lowest salary of the employees for all jobs.
select
E.JOB_ID,
count(EMPLOYEE_ID) as Number_of_Employers,
sum(salary) as Sum_of_Salary,
MAX(salary) - min(salary) as Salary_diff
from hr.jobs J
right join hr.employees E
on J.JOB_ID = E.JOB_ID
group by E.JOB_ID;