力扣(leetcode)1148和1179题(MySQL)

2023-12-24 05:44:15

1148.文章浏览I

题目链接:1148.文章浏览I
/图片

解答
# Write your MySQL query statement below
select distinct author_id as id 
from Views 
where author_id=viewer_id 
order by id;

1179.重新格式化部门表

题目链接:1179.重新格式化部门表
在这里插入图片描述

解答
# Write your MySQL query statement below
select id,
sum(case when month='Jan' then revenue end) Jan_Revenue,
sum(case when month='Feb' then revenue end) Feb_Revenue,
sum(case when month='Mar' then revenue end) Mar_Revenue,
sum(case when month='Apr' then revenue end) Apr_Revenue,
sum(case when month='May' then revenue end) May_Revenue,
sum(case when month='Jun' then revenue end) Jun_Revenue,
sum(case when month='Jul' then revenue end) Jul_Revenue,
sum(case when month='Aug' then revenue end) Aug_Revenue,
sum(case when month='Sep' then revenue end) Sep_Revenue,
sum(case when month='Oct' then revenue end) Oct_Revenue,
sum(case when month='Nov' then revenue end) Nov_Revenue,
sum(case when month='Dec' then revenue end) Dec_Revenue
from Department group by id order by id;

最后,我写了一篇MySQL教程,里面详细的介绍了MySQL的基本概念以及操作指令等内容,欢迎阅读!
MySQL数据库万字保姆级教程

文章来源:https://blog.csdn.net/qq_58737789/article/details/135174156
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。