有两张表,city表,plane_b2b表,列出部分表数据,city表字段:
        CITY_ID  HBE_CODE CITY_CN
1 1 HGH 杭州
2 2 YNJ 延吉
3 23 JMU 佳木斯
4 51 TNH 通化
5 59 JNG 济宁
plane表字段:
     plane_id  from_airport  to_airport  plane_no    
1 5 SHA   PEK      CA777
2 52 HGH   NKG      CA1234
3 60 CAN   PEK      CA123
4 112 HGH   WUH      CA211两张表关联是通过HBE_CODE与from_airport,或者HBE_CODE与to_airport(所谓的中航信三字码),现在我要按
航线(例如:杭州--济宁,两个组合是一航线)、航班号(plane_no字体)顺序排列,不知道有没谁提供点思路?注:HBE_CODE是唯一的,但plane表数据量较大,不可能plane a,plane b,city c where a.from_airport=c.hbe_code and b.from_airport=c.hbe_code取数据

解决方案 »

  1.   

    按航线(例如:杭州--济宁,两个组合是一航线)、航班号(plane_no字体)顺序排列
    是一个什么效果,给出结果排列数据
      

  2.   

    思路一、
    建立存储过程,通过临时表处理实现
    思路二、
    plane表增加航线字段,如001表示(杭州--济宁)航线以便提升查询效率好
      

  3.   

    不确定楼主要实现什么,这样不行吗:
    select * from plane1 order by from_airport,to_airport,PLANE_NO;
      

  4.   


    这样好了 用union all来做?select a.*,c.*
    plane a, city c where a.from_airport=c.hbe_code 
    select b.*,c.*
    union all
    plane b,city c where b.from_airport=c.hbe_code取数据
      

  5.   

    建一张航线和航班号对应的表,就是plane_lines(from_to,plane_no)。先对city表和plane表连接将数据导入plane_lines表。对表plane建触发器,每次有航班的添加删除或修改更新plane_lines表。
    对于plane_lines表可以建索引吧。
    我想法,估计很幼稚....
      

  6.   

    select a.*,c.*
    plane a, city c where a.from_airport=c.hbe_code  
    union all
    select b.*,c.*
    plane b,city c where b.from_airport=c.hbe_code 
      

  7.   

    要关联也是plane表与city两次连结
    plane a,city b,city c where a.from_airport=c.hbe_code and a.to_airport=c.hbe_code
    如果from_airport、to_airport、hbe_code列分别都有索引,效率应该不错
    性能主要消耗不在表连结上,而在排序上!你可以查看一下执行计划。
      

  8.   

    你单只这两个的话还好因为我这里还有好多张表跟city表关联的(问题中只列出两张),维护起来比较麻烦,之前一直以为是表连结跟数据量会影响比较大的性能,原来是排序,看来还是7楼的兄弟建索引比较理想。