当前位置: 代码迷 >> 综合 >> leetcode-Database-1179|重新格式化部门表
  详细解决方案

leetcode-Database-1179|重新格式化部门表

热度:38   发布时间:2023-12-12 12:53:06.0

原题

在这里插入图片描述

思路

不是个好题,case when。

代码

select id, sum(case `month` when 'Jan' then revenue else null end) as Jan_Revenue, sum(case `month` when 'Feb' then revenue else null end) as Feb_Revenue, sum(case `month` when 'Mar' then revenue else null end) as Mar_Revenue, sum(case `month` when 'Apr' then revenue else null end) as Apr_Revenue, sum(case `month` when 'May' then revenue else null end) as May_Revenue, sum(case `month` when 'Jun' then revenue else null end) as Jun_Revenue, sum(case `month` when 'Jul' then revenue else null end) as Jul_Revenue, sum(case `month` when 'Aug' then revenue else null end) as Aug_Revenue, sum(case `month` when 'Sep' then revenue else null end) as Sep_Revenue, sum(case `month` when 'Oct' then revenue else null end) as Oct_Revenue, sum(case `month` when 'Nov' then revenue else null end) as Nov_Revenue, sum(case `month` when 'Dec' then revenue else null end) as Dec_Revenue
from Department group by id
  相关解决方案