-
Notifications
You must be signed in to change notification settings - Fork 0
/
17_Nijat_Hajiyev_analytic_functions_part1.sql
151 lines (131 loc) · 3.39 KB
/
17_Nijat_Hajiyev_analytic_functions_part1.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
-- Task 1
/*
H?r bir i?çinin ad, soyad, maa??n? v? 4-cü
sütunda öz maa??na gör? (row_number, rank v? dense_rank) s?ras?n? ç?xar?n.
*/
select
first_name,
last_name,
salary,
row_number() over(order by salary) as row_number,
rank() over(order by salary) as rank,
dense_rank() over(order by salary) as dense_rank
from employees;
-- Task 2
/*
H?r bir i?çinin ad, soyad, maa??n? v? 4-cü sütunda
öz maa??na gör? s?ra nömr?sini ç?xar?n (h?r biri unikal).
*/
select
first_name,
last_name,
salary,
row_number() over(order by salary desc) as row_number
from employees;
-- Task 3
/*
H?r bir i?çinin ad, soyad, maa??n? v? 4-cü sütunda
öz maa??na gör? reytinqini ç?xar?n (eyni maa?lar eyni nömr?).
*/
select
first_name,
last_name,
salary,
rank() over(order by salary desc) as dense_rank
from employees;
-- Task 4
/*
H?r bir i?çinin ad, soyad, maa??n? v? 4-cü sütunda öz maa??na gör?
reytinqini ç?xar?n (eyni maa?lar eyni nömr?, bo? nömr?l?r qalmamaqla).
*/
select
first_name,
last_name,
salary,
dense_rank() over(order by salary desc) as dense_rank
from employees;
-- Task 5
/*
H?r bir i?çinin ad, soyad, maa??n? v? 4-cü sütunda öz departamenti üzr? maa??na gör?
(row_number, rank v? dense_rank) s?ras?n? ç?xar?n.
*/
select
first_name,
last_name,
salary,
department_id,
row_number() over(partition by department_id order by salary asc) as row_number,
rank() over(partition by department_id order by salary asc) as rank,
dense_rank() over(partition by department_id order by salary asc) as dense_rank
from employees;
select
first_name,
last_name,
salary,
department_id,
row_number() over(partition by department_id) as row_number,
rank() over(partition by department_id) as rank,
dense_rank() over(partition by department_id) as dense_rank
from employees
order by department_id;
-- Task 6
/*
H?r bir i?çinin ad, soyad, maa??n? v? 4-cü sütunda
öz departamenti üzr? maa??na gör? s?ra
nömr?sini ç?xar?n (h?r biri unikal)
*/
-- anlamiram suali tam
-- mence beledir
select
first_name,
last_name,
salary,
department_id,
row_number() over (partition by department_id order by salary asc)
from employees;
-- Task 7
/*
H?r bir i?çinin ad, soyad, maa??n? v? 4-cü sütunda
öz departamenti üzr? maa??na gör?
reytinqini ç?xar?n (eyni maa?lar eyni nömr?).
*/
select
first_name,
last_name,
salary,
department_id,
rank() over (partition by department_id order by salary asc)
from employees;
-- Task 8
/*
H?r bir i?çinin ad, soyad, maa??n? v? 4-cü sütunda öz departamenti üzr? maa??na gör?
reytinqini ç?xar?n (eyni maa?lar eyni nömr?, bo? nömr?l?r qalmamaqla).
*/
select
first_name,
last_name,
salary,
dense_rank() over (partition by department_id order by salary asc)
from employees;
-- Task 9
/*
H?r bir i?çinin ad, soyad?, departament_name-i v?
4-cü sütunda öz departamenti üzr? c?m maa?? ç?xar?n.
*/
select
first_name,
last_name,
department_id,
sum(salary) over(partition by department_id)
from employees;
-- Task 10
/*
H?r bir i?çinin ad, soyad?, departament_name-i v?
4-cü sütunda bütün i?çil?rin c?m maa??n? ç?xar?n.
*/
select
first_name,
last_name,
department_id,
sum(salary) over()
from employees;