怎样用SQL实现从表A到表B的变换,从表C到表D的变换,如图。

[复制链接]
查看11 | 回复4 | 2013-10-10 10:20:38 | 显示全部楼层 |阅读模式
第一个是行列转置,select student,sum(decode(subject,'语文', grade,null)) "语文",sum(decode(subject,'数学', grade,null)) "数学",sum(decode(subject,'英语', grade,null)) "英语"from tablegroup by student; 第二个当然你行数多了不行~select distinct tmp2.a,
(select b
from (SELECT a,
...
回复

使用道具 举报

千问 | 2013-10-10 10:20:38 | 显示全部楼层
其实这就是数据表列转行的问题。 A->B的转换:select name 姓名,max(case subject when '语文' then score else 0 end) as '语文',max(case subject when '数学' then score else 0 end) as '数学',max(cas...
回复

使用道具 举报

千问 | 2013-10-10 10:20:38 | 显示全部楼层
。。。又是行列转换,,,给你发个网页,自己去看下吧,,,,http://blog.csdn.net/gaofang2009/article/details/4977032...
回复

使用道具 举报

千问 | 2013-10-10 10:20:38 | 显示全部楼层
问题:假设有张学生成绩表(tb)如下:姓名 课程 分数张三 语文 74张三 数学 83张三 物理 93李四 语文 74李四 数学 84李四 物理 94想变成(得到如下结果):姓名 语文 数学 物理---- ---- ---- ----李四 74 84 94张三 74 83 93-------...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行