Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Leetcode 569. Median Employee Salary
--PostgreSQL 9.6 --'\\' is a delimiter drop table if Exists Employee; Create table Employee("id" int, "company" varchar(30), "salary" int); insert into Employee("id", "company", "salary") values (1, 'A', 2341), (2, 'A', 341), (3, 'A', 15), (4, 'A', 15314), (5, 'A', 451), (6, 'A', 513), (7, 'B', 15), (8, 'B', 13), (9, 'B', 1154), (10, 'B', 1345), (11, 'B', 1221), (12, 'B', 234), (13, 'C', 2345), (14, 'C', 2645), (15, 'C', 2645), (16, 'C', 2652), (17, 'C', 65); select Id, company, salary from ( select Id, company, salary, row_number() over(partition by company order by salary asc) as asc_rownum, row_number() over(partition by company order by salary desc) as desc_rownum from employee ) as subq where subq.asc_rownum in (subq.desc_rownum - 1, subq.desc_rownum + 1, subq.desc_rownum)
run
|
edit
|
history
|
help
0
quiz 1
Assignment 1(SET A)
Shortest "path" between two employees across companies
Dashes in numbers
SQL Movie-Rating Query Exercises
sample
PostreSQL: Today's Date/Time
funkcia_transakcie
Movie Rating SQL Analysis Project
Return IDs where there are exactly 3 occurrences1