【MySQL刷题笔记】leetcode难度为简单的题

1179.Reformat Department Table

就是表的转置

select id,
max(case month when 'Jan' then revenue else null end)Jan_Revenue,
max(case month when 'Feb' then revenue else null end)Feb_Revenue,
max(case month when 'Mar' then revenue else null end)Mar_Revenue,
max(case month when 'Apr' then revenue else null end)Apr_Revenue,
max(case month when 'May' then revenue else null end)May_Revenue,
max(case month when 'Jun' then revenue else null end)Jun_Revenue,
max(case month when 'Jul' then revenue else null end)Jul_Revenue,
max(case month when 'Aug' then revenue else null end)Aug_Revenue,
max(case month when 'Sep' then revenue else null end)Sep_Revenue,
max(case month when 'Oct' then revenue else null end)Oct_Revenue,
max(case month when 'Nov' then revenue else null end)Nov_Revenue,
max(case month when 'Dec' then revenue else null end)Dec_Revenue 
from department group by id;

运行结果:
【MySQL刷题笔记】leetcode难度为简单的题_第1张图片

181. Employees Earning More Than Their Managers

select e1.Name as Employee from Employee e1, Employee e2 
where e1.ManagerId=e2.Id and e1.salary>e2.salary;

182. Duplicate Emails

select Email from person group by email having count(*)>1;

【MySQL刷题笔记】leetcode难度为简单的题_第2张图片

197. Rising Temperature

select w1.id from weather w1, weather w2 where w2.RecordDate=date_sub(w1.RecordDate,interval 1 day) and w1.temperature>w2.temperature;

【MySQL刷题笔记】leetcode难度为简单的题_第3张图片

你可能感兴趣的:(MySQL)