diff --git a/Department_top3_Salaries.sql b/Department_top3_Salaries.sql new file mode 100644 index 0000000..aa6ac0e --- /dev/null +++ b/Department_top3_Salaries.sql @@ -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) \ No newline at end of file diff --git a/ExchangeSeats.sql b/ExchangeSeats.sql new file mode 100644 index 0000000..3f63361 --- /dev/null +++ b/ExchangeSeats.sql @@ -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 \ No newline at end of file diff --git a/RankScores.sql b/RankScores.sql new file mode 100644 index 0000000..578adbd --- /dev/null +++ b/RankScores.sql @@ -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; \ No newline at end of file diff --git a/TreeNode.sql b/TreeNode.sql new file mode 100644 index 0000000..02854b8 --- /dev/null +++ b/TreeNode.sql @@ -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 \ No newline at end of file