17,377
社区成员
发帖
与我相关
我的任务
分享
create table test_c("id" varchar2(20),"date" date,city varchar2(20),op varchar2(20));
insert into test_c values ('0680013620',date'2006-8-21','南昌市','AAAA');
insert into test_c values ('0680013620',date'2006-8-21','杭州市','BBBB');
insert into test_c values ('0680013620',date'2007-3-1','广州市','CCCC');
insert into test_c values ('0680013620',date'2006-8-21','南昌市','DDDD');
insert into test_c values ('0680013620',date'2006-8-21','南昌市','EEEE');
insert into test_c values ('0680013621',date'2006-8-21','南昌市','AAAA');
insert into test_c values ('0680013621',date'2006-8-21','杭州市','BBBB');
insert into test_c values ('0680013622',date'2007-3-1','广州市','AAAA');
insert into test_c values ('0680013622',date'2006-8-21','南昌市','BBBB');
insert into test_c values ('0680013622',date'2006-8-21','南昌市','CCCC');
select "id" ,max(decode(op,'AAAA',city)) city,
max(decode(op,'AAAA',"date")) AAAA,
max(decode(op,'BBBB',"date")) BBBB,
max(decode(op,'CCCC',"date")) CCCC,
max(decode(op,'DDDD',"date")) DDDD,
max(decode(op,'EEEE',"date")) EEEE
from test_c
group by "id"
id CITY AAAA BBBB CCCC DDDD EEEE
0680013620 南昌市 2006-8-21 2006-8-21 2007-3-1 2006-8-21 2006-8-21
0680013621 南昌市 2006-8-21 2006-8-21
0680013622 广州市 2007-3-1 2006-8-21 2006-8-21