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相关推荐

  1. LeetCode知识点总结 - 884

    LeetCode 884. Uncommon Words from Two Sentences 考点 难度 Hash Table Easy 题目 A sentence is a string of s ...

  2. LeetCode知识点总结 - 868

    LeetCode 868. Binary Gap 考点 难度 Math Easy 题目 Given a positive integer n, find and return the longest ...

  3. LeetCode知识点总结 - 1413

    LeetCode 1413. Minimum Value to Get Positive Step by Step Sum 考点 难度 Prefix Sum Easy 题目 Given an arra ...

  4. LeetCode知识点总结 - 2073

    LeetCode 2073. Time Needed to Buy Tickets 考点 难度 Simulation Easy 题目 There are n people in a line queu ...

  5. LeetCode知识点总结 - 347

    LeetCode 347. Top K Frequent Elements 考点 难度 Array Medium 题目 Given an integer array nums and an integ ...

  6. LeetCode知识点总结 - 997

    LeetCode 997. Find the Town Judge 考点 难度 Hash Table Easy 题目 In a town, there are n people labeled fro ...

  7. LeetCode知识点总结 - 606

    LeetCode 606. Construct String from Binary Tree 考点 难度 String Easy 题目 Given the root of a binary tree ...

  8. LeetCode知识点总结 - 844

    LeetCode 844. Backspace String Compare 考点 难度 Simulation Easy 题目 Given two strings s and t, return tr ...

  9. LeetCode知识点总结 - 977

    LeetCode 977. Squares of a Sorted Array 考点 难度 Sorting Easy 题目 Given an integer array nums sorted in ...

  10. LeetCode知识点总结 - 377

    LeetCode 377. Combination Sum IV 考点 难度 DP Medium 题目 Given an array of distinct integers nums and a t ...

最新文章

  1. ALV 刷新实现(自动)
  2. win10磁盘检查命令
  3. infoseccrypto_java下载_關於php接ICBC的支付接口的解決方案
  4. Win11代言人官宣
  5. Oracle 大规模 delete,update 操作 注意事项
  6. mysql command line client闪一下消失
  7. [Usaco2006 Open]County Fair Events 参加节日庆祝
  8. 半自动驾驶大对决:特斯拉和凯迪拉克谁是真王
  9. 第一周 从C走进C++ 002 命令行参数
  10. 5. Zend_Log
  11. SQLite.Net操作类
  12. notepad如何自动对齐_notepad怎么对齐
  13. 史上最强三千六百道脑筋急转弯(3)
  14. [渝粤教育] 中国地质大学 砌体结构设计 复习题 (2)
  15. Oracle-数据库的备份与恢复
  16. Apache web服务器 的下载安装
  17. 人工智能传奇—关于AI起源与发展的故事
  18. 西门子real是什么数据类型_西门子数据类型REAL转WORD和S5TIME的方法
  19. basler相机出现buffer不足的解决方案
  20. 总结vicky写的增删div

热门文章

  1. 从小程序升级成独立APP,“小鹅拼拼”如何帮鹅厂“拼”未来?
  2. springboot毕设项目热贡文化艺术展示与定制s5g19(java+VUE+Mybatis+Maven+Mysql)
  3. 2020十大高薪资专业和十大高薪资岗位---(之我给程序员丢人了)
  4. 二进制与十进制的讲解与转换
  5. 解决 Web、软件 视频播放黑屏
  6. Linux远程服务器环境搭建
  7. 信息安全技术国家相关标准一览表
  8. 基于java的拼图游戏的设计与实现
  9. python实现图片切割及拼图游戏
  10. python 面积计算器