SQL题:请用一条SQL查询(ORACLE)语言实现行列转换

2025-03-23 19:43:01
推荐回答(2个)
回答1:

还是这道题啊,如果只是针对本题,可以用以下的SQL语句

select 姓名,
sum(case 学科 when '语文' then 成绩 end) as 语文,
sum(case 学科 when '数学' then 成绩 end) as 数学,
sum(case 学科 when '物理' then 成绩 end) as 物理
from cj group by 姓名

回答2:

yclfwm 给我加分哦!(-1 表示没有成绩记录)
select student,nvl(sum(yuwen),-1) as yuwen,nvl(sum(shuxue),-1) as shuxue,nvl(sum(wuli),-1) as wuli
from ( select student,
case when cource='yuwen' then mark else null end as yuwen,
case when cource='shuxue' then mark else null end as shuxue,
case when cource='wuli' then mark else null end as wuli
from bob_cj )
group by student
order by student