日期:2014-05-16 浏览次数:20844 次
WITH jiangxi AS ( SELECT 1 id,'南昌' city FROM DUAL UNION ALL SELECT 2 id,'九江' city FROM DUAL ),hubei AS ( SELECT 1 id,'武?' city FROM DUAL UNION ALL SELECT 2 id,'襄?' city FROM DUAL ),start_tb AS ( SELECT 1 id,'上海' sfrom,'jiangxi' viaFrom FROM DUAL UNION ALL SELECT 2 id,'上海' sfrom,'beijing' viaFrom FROM DUAL UNION ALL SELECT 3 id,'上海' sfrom,'hubei' viaFrom FROM DUAL UNION ALL SELECT 4 id,'上海' sfrom,'shandong' viaFrom FROM DUAL ),dest_tb AS ( SELECT 1 id,'成都' dest,'北平' viaTo FROM DUAL UNION ALL SELECT 2 id,'南充' dest,'武?' viaTo FROM DUAL UNION ALL SELECT 3 id,'宜?' dest,'广州' viaTo FROM DUAL UNION ALL SELECT 4 id,'?州' dest,'九江' viaTo FROM DUAL ) SELECT s.sfrom, jh.via, d.viaTo viacity, d.dest FROM dest_tb d, ( SELECT 'jiangxi' via,city FROM jiangxi UNION ALL SELECT 'hubei' via,city FROM hubei ) jh, start_tb s WHERE d.viaTo = jh.city AND jh.via = s.viaFrom;
------解决方案--------------------
select a.from,b.viaFrom as via, b.city as viacity ,c.dest
from start a ,(
select 'jiangxi' as viaFrom, city from jiangxi
union all
select 'hubei' as viaFrom, city from hubei
) b ,dest c
where a.viaFrom=b.viaFrom
and b.city=c.viaTo