File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ -- Employee Table
3
+ -- - id
4
+ -- - first_name
5
+ -- - last_name
6
+ -- - salary
7
+ -- - dept_id
8
+
9
+
10
+ -- Departement
11
+ -- - id
12
+ -- - name
13
+
14
+
15
+ -- Find top 3 dept , atleast 10 employees and rank them acc to % employees making 100000 in salary
16
+
17
+ -- Output - %perc(10000000), deptname, nos_of_employees
18
+
19
+ with cte as (
20
+ select e.* , d .name as dept_name rank() partition_by(d .dept_id order by e .salary desc ) rnk
21
+ from employee e join Departement d on e .dept_id = d .dept_id
22
+ )
23
+ select
24
+ (count (case when salary >= 100000 then 1 else 0 end) * 100 .0 ) / count (id) as ' %perc_salary' ,
25
+ dept_name,
26
+ count (case when salary >= 100000 then 1 else 0 end) as no_of_employees
27
+ from cte group by dept_id having rnk <= 3 and count (id) >= 10 order by ' %perc_salary' desc
28
+
You can’t perform that action at this time.
0 commit comments