数据仓库服务 GAUSSDB(DWS)-DWS如何实现行转列及列转行?:静态行转列
时间:2025-04-17 08:12:54
静态行转列
静态行转列需要手动指定每一列的列名,如果存在则取其对应值,否则将赋其默认值0。
1 2 3 4 5 6 7 8 9 10 |
SELECT name, sum(case when subject='math' then score else 0 end) as math, sum(case when subject='physics' then score else 0 end) as physics, sum(case when subject='literature' then score else 0 end) as literature FROM students_info GROUP BY name; name | math | physics | literature ------+------+---------+------------ matu | 75 | 90 | 85 lily | 95 | 80 | 92 jack | 90 | 95 | 95 (3 rows) |
support.huaweicloud.com/dws_faq/dws_03_2110.html
推荐文章