【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;

运行结果:
在这里插入图片描述

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;

在这里插入图片描述

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;

在这里插入图片描述

发布了390 篇原创文章 · 获赞 27 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/AXIMI/article/details/104312634
今日推荐