Skip to content
Open
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
32 changes: 32 additions & 0 deletions HW2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Problem Rank Scores

# Write your MySQL query statement below
select score, DENSE_RANK() OVER(ORDER BY score desc) as 'rank' from Scores;




# Problem Exchange Seats

Solution:
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;


# Tree Problem

select id, if(ISNULL(p_id),'Root',if(id in(select distinct p_id from Tree),'Inner','Leaf')) as 'Type' from Tree;


# Department top 3 Salaries

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;