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
21 changes: 21 additions & 0 deletions PRoblem4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
WITH cte AS (
SELECT
d.name AS Department,
e.name AS Employee,
e.salary AS Salary,
DENSE_RANK() OVER (
PARTITION BY e.departmentId
ORDER BY e.salary DESC
) AS salary_rank
FROM Employee e
LEFT JOIN Department d
ON e.departmentId = d.id
)
SELECT
Department,
Employee,
Salary
FROM cte
WHERE salary_rank <= 3
ORDER BY Department, Salary DESC;

8 changes: 8 additions & 0 deletions Problem1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Write your MySQL query statement below
-- 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;

SELECT s.score, COUNT(DISTINCT T.score) AS 'rank'
FROM scores s JOIN scores T ON s.score<=T.score
GROUP BY s.id ORDER BY S.SCORE DESC;
10 changes: 10 additions & 0 deletions Problem2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Write your MySQL query statement below
-- SELECT count(id) from FROM seats;
-- SELECT MOD(id,2) AS 'mod' from seat;
-- SELECT (
-- CASE
-- WHEN mod(id,2) !=0 AND id!=cnts THEN id+1
-- WHEN mod(id,2) !=0 AND id =cnts THEN id
-- ELSE id-1
-- END) AS 'id' ,student FROM Seat, (SELECT COUNT(*) as 'cnts' FROM Seat) AS SEAT_COUNTS ORDER BY ID;
select s1.id, COALESCE (s2.student, s1.student) AS'student' FROM seat s1 LEFT JOIN seat s2 ON (s1.id +1)^1-1 = s2.id ORDER BY s1.id;
9 changes: 9 additions & 0 deletions Problem3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Write your MySQL query statement below

SELECT id, (
CASE
WHEN p_id is NULL THEN 'Root'
When id NOT IN (SELECT DISTINCT p_id FROM tree WHERE p_id IS NOT NULL) AND p_id is NOT NULL THEN 'Leaf'
ELSE 'Inner'
END
) AS 'type' FROM tree;