我现在做一个公交乘换查询程序。
假如起点为A, 终点为Z,
现在要搜索出A-Z的直达线路和倒一次车的线路
有什么好的思路。还望大家给些建议。thanks!

解决方案 »

  1.   

    select * from table where 起点 = 'A' and 终点 = 'Z'UNIONselect * from table a where 起点 = 'A' and 终点 in (select 起点 from table where 起点 <> 'A' and 终点 = 'Z')
      

  2.   

    3 楼的后半部分可以优化为select t1.* from table t1
      left join table t2 on t2.起点=t1.终点
    where t1.起点='A' and t2.重点='Z'
      

  3.   

    去我的空间看
    http://blog.csdn.net/lastsweetop/archive/2008/03/06/2153670.aspx
    这属于寻路问题
      

  4.   

         表 gj_xianlu       字段名有 xl_name, xl_type, xl_beizhu
         表  xianlu_sx       字段名有 sx_xl_name, sx_zd_name, sx_order
                   
      

  5.   

    我的表达能力比较弱点。请大家见谅。
    我的数据库是这样的 
          线路基本信息表  gj_xianlu       字段名有 xl_name, xl_type, xl_beizhu 
          站点表         gj_zhandian     字段名有 zd_name, zd_type, zd_beizhu
         线路表(关联表)  xianlu_sx       字段名有 sx_xl_name, sx_zd_name, sx_order 
    其他表就不写了。
          通过关联表管理线路。