LeetCode MySQL刷题——day3
生活随笔
收集整理的這篇文章主要介紹了
LeetCode MySQL刷题——day3
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
一、重新格式化部門表
1、題目描述
2、題解
3、源碼
二、第二高的薪資
1、題目描述
2、題解
3、源碼
?三、第n高的薪水
1、題目描述
2、題解
3、源碼
?四、分數(shù)排名
1、題目描述
2、題解
3、源碼
五、連續(xù)出現(xiàn)的數(shù)
1、題目描述
2、題解
?3、源碼
一、重新格式化部門表
1、題目描述
?
2、題解
3、源碼
# Write your MySQL query statement below select id,sum(case month when 'Jan' then revenue end) as Jan_Revenue,sum(case month when 'Feb' then revenue end) as Feb_Revenue,sum(case month when 'Mar' then revenue end) as Mar_Revenue,sum(case month when 'Apr' then revenue end) as Apr_Revenue,sum(case month when 'May' then revenue end) as May_Revenue,sum(case month when 'Jun' then revenue end) as Jun_Revenue,sum(case month when 'Jul' then revenue end) as Jul_Revenue,sum(case month when 'Aug' then revenue end) as Aug_Revenue,sum(case month when 'Sep' then revenue end) as Sep_Revenue,sum(case month when 'Oct' then revenue end) as Oct_Revenue,sum(case month when 'Nov' then revenue end) as Nov_Revenue,sum(case month when 'Dec' then revenue end) as Dec_Revenue from Department group by id二、第二高的薪資
1、題目描述
?
2、題解
?
3、源碼
# Write your MySQL query statement below # select ifNull( # (select distinct salary # from Employee # order by Salary Desc # limit 1,1),null # ) as SecondHighestSalary;select max(distinct salary) as SecondHighestSalary from Employee where salary < (select max(distinct salary)from Employee);# select max(distinct 成績) # from 成績表 # where 課程='語文' and # 成績 < (select max(distinct 成績) # from 成績表 # where 課程='語文');?三、第n高的薪水
1、題目描述
?
2、題解
3、源碼
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGINSET N :=N-1;RETURN (# Write your MySQL query statement below.SELECT salary FROM Employeegroup by salaryORDER by salary DESCLIMIT N,1) ; END?四、分數(shù)排名
1、題目描述
?
?
2、題解
3、源碼
selectscore,(dense_rank() over (order by Score desc)) AS "rank" fromScores五、連續(xù)出現(xiàn)的數(shù)
1、題目描述
2、題解
?3、源碼
# Write your MySQL query statement below select distinctNum as ConsecutiveNums from (select Num,Id-cast((row_number() over(partition by Num order by Id asc)) as signed) as ranking from Logs) as t group by Num,ranking having count(*)>=3總結
以上是生活随笔為你收集整理的LeetCode MySQL刷题——day3的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring源码研究
- 下一篇: sql where 1=1和 0=1 的