求助:一道练习题sql语句怎么写?

2025-02-26 03:48:44
推荐回答(2个)
回答1:

select a.name,a.score 语文,b.score 化学,c.score 英语 from
(select name,score from student where course='语文' ) a
left join
(select name,score from student where course='化学' ) b
on a.name=b.name
left join
(select name,score from student where course='英语' ) c
on a.name = c.name

回答2:

select name,case when course='语文' then score end as '语文',
case when course='化学' then score end as '化学',
case when course='英语' then score end as '英语'
from student;
这是列转行,行转列的话用UNION ALL