select RECORD_ID AS ID,STU_NAME AS 姓名, STU_NO AS 学号,'语文' AS 科目,CHINESE AS 成绩 from TM_STU a where STU_NO in (select STU_NO from TM_STU) union all
select RECORD_ID AS ID,STU_NAME AS 姓名, STU_NO AS 学号,'数学' AS 科目,[MATH] AS 成绩 from TM_STU a where STU_NO in (select STU_NO from TM_STU) union all
select RECORD_ID AS ID,STU_NAME AS 姓名, STU_NO AS 学号,'英语' AS 科目,ENGLISH AS 成绩 from TM_STU a where STU_NO in (select STU_NO from TM_STU) ORDER BY RECORD_ID
额..我开始也是查到这个... 但是这个不是开窗函数吧,... 我想要的就是用开窗函数和分析函数...
sum(decode(t.course, '语文', score, null)) as "语文"
比如decode 这些函数...
算了, 你这个我学到了不少哦.. 呵呵..谢谢了...虽然没得到我要的答案...晚点我会把我的答案公布... 我再研究研究...
你这个不就是列转行么,给你个地址:http://www.2cto.com/database/201108/100792.html
这里面行转列,列转行都有啦!
这就是最常见的列转行,主要原理是利用SQL里面的union
要求是开窗函数和分析函数啊... 如果是这种方法的话, 早回了....
@ζ 简单ヾ°:你是在找这种?
select student,sum(decode(subject,'语文', grade,null)) "语文",
sum(decode(subject,'数学', grade,null)) "数学",
sum(decode(subject,'英语', grade,null)) "英语"
from table
group by student
@Alex_QY1987: 这是另外一个题的.. 嗯.. 是这种样子... 呵呵...