Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Department_top3_Salaries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
WITH CTE as(
SELECT d.name as 'department',d.id as'did', e.name as 'employee', e.salary as 'salary' from employee e left join department d ON e.departmentId = d.id
)
SELECT department, employee, salary from CTE c
where 3> (Select count(DISTINCT e2.salary)from employee e2 where c.did = e2.departmentId and e2.salary>c.salary)
9 changes: 9 additions & 0 deletions ExchangeSeats.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT(
CASE
WHEN MOD(id,2) !=0 AND id = cnts THEN id
WHEN MOD(id,2) !=0 AND id !=cnts THEN id+1
ELSE id-1
END
) as 'id', student from seat,
(SELECT COUNT(*) AS 'cnts' from seat) as seat_counts
ORDER BY id
5 changes: 5 additions & 0 deletions RankScores.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT s1.score,
(SELECT COUNT(DISTINCT s2.score) FROM scores s2
WHERE s2.score>=s1.score)
AS 'rank' FROM scores s1
ORDER BY s1.score DESC;
6 changes: 6 additions & 0 deletions TreeNode.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT id, 'Root' as type from tree where p_id is null
UNION
Select id, 'Leaf' as type from tree where id NOT IN (Select Distinct p_id from tree where p_id is not null) And p_id is not null
UNION
Select id, 'Inner' as type from tree where id IN (Select Distinct p_id from tree where p_id is not null) And p_id is not null
Order by id