建成绩表gradeinfo和学生表student,成绩表中存有学生表的id:

 

create table GRADEINFO
(
  SID     VARCHAR2(2),
  SUBJECT VARCHAR2(20),
  GRADE   VARCHAR2(20)
)

 

 

create table STUDENT
(
  ID   VARCHAR2(2),
  NAME VARCHAR2(20)
)

 要查询出每一个学生对应的每一门功课的分数是多少。

 想要的效果如下:


oracle行转列sql

查询SQL:

 

select a.name,sum(decode(b.subject,'语文', b.grade)) "语文",
sum(decode(b.subject,'数学', b.grade)) "数学",
sum(decode(b.subject,'英语', b.grade)) "英语"
from student a,gradeinfo b where b.sid=a.id
group by a.name

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2021-04-10
  • 2022-01-12
  • 2022-12-23
猜你喜欢
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
相关资源
相似解决方案