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

来源:互联网 发布:淘宝宝马摩托车 编辑:程序博客网 时间:2024/05/21 10:24
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 servicesscheduleselect '002','4155526710',1,'01',date '1994-07-16' from dual union allselect '002','4155526710',2,'01',date '1994-07-30' from dual union allselect '002','4155526710',3,'01',date '1994-10-01' from dual union allselect '002','4155526711',1,'01',date '1994-07-16' from dual union allselect '002','4155526711',2,'01',date '1994-07-30' from dual union allselect '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))

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

这就是个行转列

原创粉丝点击