标签:
建表:
create table studentinfo(
name varchar(20) ,
subject varchar(20),
score number(3,1));
插入记录:
insert into studentinfo values(‘张三‘,‘语文‘,69);
insert into studentinfo values(‘张三‘,‘数学‘,70);
insert into studentinfo values(‘李四‘,‘语文‘,20);
里面的记录为:
我们想要的结果为:
通过下面的sql可以实现:
select a 姓名,max(a1) 语文,max(a2) 数学
from (
select a, case when b = ‘语文‘ then c else null end as a1,
case when b = ‘数学‘ then c else null end as a2
from
(select name a,subject b,score c from studentinfo) x
) y
group by a;
标签:
原文地址:http://www.cnblogs.com/caobotao/p/4981230.html