FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SQL/Second_High_Salary_In_Each_Dept.sql at master · SimonFans/SQL · GitHub
SimonFans
/
SQL
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
20
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SQL
/
Second_High_Salary_In_Each_Dept.sql
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (27 loc) · 1.27 KB
Breadcrumbs
SQL
/
Second_High_Salary_In_Each_Dept.sql
Copy path
File metadata and controls
31 lines (27 loc) · 1.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
CoderPad provides a basic SQL sandbox with the following schema.
You can also use commands like `show tables` and `desc employees`
employees projects
+---------------+---------+ +---------------+---------+
| id | int |<----+ +->| id | int |
| first_name | varchar | | | | title | varchar |
| last_name | varchar | | | | start_date | date |
| salary | int | | | | end_date | date |
| department_id | int |--+ | | | budget | int |
+---------------+---------+ | | | +---------------+---------+
| | |
departments | | | employees_projects
+---------------+---------+ | | | +---------------+---------+
| id | int |<-+ | +--| project_id | int |
| name | varchar | +-----| employee_id | int |
+---------------+---------+ +---------------+---------+
*/
SELECT
tb1.
*
FROM
employees tb1
JOIN
departments tb2
ON
tb1
.
department_id
=
tb2
.
id
WHERE
(
select
count
(distinct(
tb3
.
salary
))
from
employees tb3
where
tb3
.
salary
>
tb1
.
salary
and
tb1
.
department_id
=
tb3
.
department_id
)
=
1
;
Back
|
FazBrowse Home
|
New Git URL