本人數據庫不熟,拜托大家了
這是原始數據庫裡的數據
這是sql運行後的效果
QQ郵件我已經回復你了
create table TEST
(
ADDRESS VARCHAR2(20),
TYPE VARCHAR2(20),
DETAIL VARCHAR2(20)
);
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('上海', '閘北', 'A地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('上海', '寶山', 'A地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('上海', '普陀', 'A地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('上海', '浦東', 'A地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('河南', '周口', 'A地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('河南', '鄭州', 'A地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('河南', '駐馬店', 'A地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('河南', '洛陽', 'A地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('上海', '閘北', 'B地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('上海', '寶山', 'B地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('上海', '普陀', 'B地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('上海', '浦東', 'B地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('河南', '周口', 'B地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('河南', '鄭州', 'B地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('河南', '駐馬店', 'B地');
insert into TEST (ADDRESS, TYPE, DETAIL)
values ('河南', '洛陽', 'B地');
commit;
select nvl2(type, '', address) address, type, detail
from (select distinct address, '' type, '' detail
from test
union
select address, type, null detail
from test
group by type, address
union
select address, type, detail
from test
order by address, type desc, detail desc);
效果圖