列转行--行转列问题(3)
来源:未知 责任编辑:责任编辑 发表时间:2014-03-23 22:32 点击:次
Nike 0 0 0 85
Kent 80 0 0 0
Kent 0 90 0 0
Kent 0 0 70 0
Kent 0 0 0 85
下一步,聚合分组,最终完成任务。
令一种实现方式:
SELECT
UserName,
sum(decode(subject,'语文',score,0)) AS "语文",
sum(decode(subject,'数学',score,0)) AS "数学",
sum(decode(subject,'英语',score,0)) AS "英语",
sum(decode(subject,'生物',score,0)) AS "生物"
FROM StudentScores www.2cto.com
GROUP BY UserName;
问题:实现列转行
解决:
1、准备数据:
create table ScoresStudent as SELECT
UserName,
sum(decode(subject,'语文',score,0)) AS "语文",
sum(decode(subject,'数学',score,0)) AS "数学",
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>