LeetCode知识点总结 - 1179
LeetCode 1179. Reformat Department Table
考点 | 难度 |
---|---|
Database | Easy |
题目
Write an SQL query to reformat the table such that there is a department id column and a revenue column for each month.
Return the result table in any order.
思路
因为group by
需要一个aggregate function,所以用sum
。
答案
select id,
sum(case when month = 'Jan' then revenue else null end) as Jan_Revenue,
sum(case when month = 'Feb' then revenue else null end) as Feb_Revenue,
sum(case when month = 'Mar' then revenue else null end) as Mar_Revenue,
sum(case when month = 'Apr' then revenue else null end) as Apr_Revenue,
sum(case when month = 'May' then revenue else null end) as May_Revenue,
sum(case when month = 'Jun' then revenue else null end) as Jun_Revenue,
sum(case when month = 'Jul' then revenue else null end) as Jul_Revenue,
sum(case when month = 'Aug' then revenue else null end) as Aug_Revenue,
sum(case when month = 'Sep' then revenue else null end) as Sep_Revenue,
sum(case when month = 'Oct' then revenue else null end) as Oct_Revenue,
sum(case when month = 'Nov' then revenue else null end) as Nov_Revenue,
sum(case when month = 'Dec' then revenue else null end) as Dec_Revenue
from department
group by id;
LeetCode知识点总结 - 1179相关推荐
- LeetCode知识点总结 - 884
LeetCode 884. Uncommon Words from Two Sentences 考点 难度 Hash Table Easy 题目 A sentence is a string of s ...
- LeetCode知识点总结 - 868
LeetCode 868. Binary Gap 考点 难度 Math Easy 题目 Given a positive integer n, find and return the longest ...
- LeetCode知识点总结 - 1413
LeetCode 1413. Minimum Value to Get Positive Step by Step Sum 考点 难度 Prefix Sum Easy 题目 Given an arra ...
- LeetCode知识点总结 - 2073
LeetCode 2073. Time Needed to Buy Tickets 考点 难度 Simulation Easy 题目 There are n people in a line queu ...
- LeetCode知识点总结 - 347
LeetCode 347. Top K Frequent Elements 考点 难度 Array Medium 题目 Given an integer array nums and an integ ...
- LeetCode知识点总结 - 997
LeetCode 997. Find the Town Judge 考点 难度 Hash Table Easy 题目 In a town, there are n people labeled fro ...
- LeetCode知识点总结 - 606
LeetCode 606. Construct String from Binary Tree 考点 难度 String Easy 题目 Given the root of a binary tree ...
- LeetCode知识点总结 - 844
LeetCode 844. Backspace String Compare 考点 难度 Simulation Easy 题目 Given two strings s and t, return tr ...
- LeetCode知识点总结 - 977
LeetCode 977. Squares of a Sorted Array 考点 难度 Sorting Easy 题目 Given an integer array nums sorted in ...
- LeetCode知识点总结 - 377
LeetCode 377. Combination Sum IV 考点 难度 DP Medium 题目 Given an array of distinct integers nums and a t ...
最新文章
- ALV 刷新实现(自动)
- win10磁盘检查命令
- infoseccrypto_java下载_關於php接ICBC的支付接口的解決方案
- Win11代言人官宣
- Oracle 大规模 delete,update 操作 注意事项
- mysql command line client闪一下消失
- [Usaco2006 Open]County Fair Events 参加节日庆祝
- 半自动驾驶大对决:特斯拉和凯迪拉克谁是真王
- 第一周 从C走进C++ 002 命令行参数
- 5. Zend_Log
- SQLite.Net操作类
- notepad如何自动对齐_notepad怎么对齐
- 史上最强三千六百道脑筋急转弯(3)
- [渝粤教育] 中国地质大学 砌体结构设计 复习题 (2)
- Oracle-数据库的备份与恢复
- Apache web服务器 的下载安装
- 人工智能传奇—关于AI起源与发展的故事
- 西门子real是什么数据类型_西门子数据类型REAL转WORD和S5TIME的方法
- basler相机出现buffer不足的解决方案
- 总结vicky写的增删div