您的位置:首页 > 数据库

sql解惑之里程碑 谜题25(行转列)

2013-07-25 12:03 197 查看
create table servicesschedule
(
shop_id char(3) not null,
order_nbr char(10) not null,
sch_seq integer not null check(sch_seq in (1,2,3)),
service_type char(2) not null,
sch_date date,
primary key(shop_id,order_nbr,sch_seq)
)

insert into servicesschedule
select '002','4155526710',1,'01',date '1994-07-16' from dual union all
select '002','4155526710',2,'01',date '1994-07-30' from dual union all
select '002','4155526710',3,'01',date '1994-10-01' from dual union all
select '002','4155526711',1,'01',date '1994-07-16' from dual union all
select '002','4155526711',2,'01',date '1994-07-30' from dual union all
select '002','4155526711',3,'01',null from dual;

select order_nbr, "1" as proc, "2" as com, "3" as con
from (select order_nbr, sch_seq, sch_date from servicesschedule)
/**/ pivot(max(sch_date) for sch_seq in(1, 2, 3))

有人说这个题没看懂,抛砖引玉一下

这就是个行转列
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: