- 给出一个数据表(rainfall)
把此表改成以下的格式
2.解题思路
首先使标题行变化按id分组,之后把常量用case语句填入值,之后按id分组后取每个列的最大值就是最后结果了。
代码如下select id, MAX(case ctime when '3h' then ccount else 0 end) as '3h', MAX(case ctime when '6h' then ccount else 0 end) as '6h', MAX(case ctime when '9h' then ccount else 0 end) as '9h', MAX(case ctime when '12h' then ccount else 0 end) as '12h' FROM rainfall GROUP BY id;
sql实现行列互换
最新推荐文章于 2024-06-25 17:09:50 发布