上面的结果集我就是用这个SQL语句取出来的
select wholecoach.start_date as 开班日期,wholecoach.runline as 运行线路,wholecoach.price as 票价,fare.station as 站名,wholecoach.direction as 方向,station.distance as 里程,station.type1 as 省份 from fare,wholecoach,station where fare.code=wholecoach.runline and fare.memorial=station.memorial and wholecoach.terminal='荆门'

解决方案 »

  1.   

    select * from 表 tem where 开班日期=(select max(开班日期) from 表 where 站名=tem.站名)
      

  2.   

    select * from (
    select wholecoach.start_date as 开班日期,wholecoach.runline as 运行线路,wholecoach.price as 票价,fare.station as 站名,wholecoach.direction as 方向,station.distance as 里程,station.type1 as 省份 from fare,wholecoach,station where fare.code=wholecoach.runline and fare.memorial=station.memorial and wholecoach.terminal='荆门'
    ) tem where 开班日期=(select max(wholecoach.start_date) from fare,wholecoach where wholecoach.terminal='荆门' and  fare.code=wholecoach.runline and fare.station=tem.站名)
      

  3.   

    select * from(
    select wholecoach.start_date as 开班日期,wholecoach.runline as 运行线路,wholecoach.price as 票价,fare.station as 站名,wholecoach.direction as 方向,station.distance as 里程,station.type1 as 省份 from fare,wholecoach,station where fare.code=wholecoach.runline and fare.memorial=station.memorial and wholecoach.terminal='荆门'
    ) a where 开班日期=(select max(开班日期) from(
    select wholecoach.start_date as 开班日期,wholecoach.runline as 运行线路,wholecoach.price as 票价,fare.station as 站名,wholecoach.direction as 方向,station.distance as 里程,station.type1 as 省份 from fare,wholecoach,station where fare.code=wholecoach.runline and fare.memorial=station.memorial and wholecoach.terminal='荆门'
    ) a where 站名=a.站名)
      

  4.   

    select * from 表 a where 开班日期=(select max(开班日期) from 表 where 站名=a.站名 and a.线路代码=线路代码)
      

  5.   

    原理就是:select * from 表 tem where 开班日期=(select max(开班日期) from 表 where 站名=tem.站名)楼主看懂的话应该会自己改的。
      

  6.   

    算了算了哥哥们,帮我把这个问题搞定了是一样的。
    select fare.station as 站名,wholecoach.price as 票价 from wholecoach,fare,station where wholecoach.terminal='荆门' and wholecoach.runline=fare.code and fare.memorial=station.memorial group by fare.station,wholecoach.price order by wholecoach.price
    上面的语句得到:
    广华寺 .0000
    荆门 .0000
    李市 .0000
    龙尾山 .0000
    七里湖 .0000
    钱场 .0000
    沙洋 .0000
    雁门口 .0000
    杨家丰 .0000
    易家岭 .0000
    皂市 .0000
    广华寺 52.0000
    荆门 52.0000
    李市 52.0000
    沙洋 52.0000
    广华寺 54.5000
    荆门 54.5000
    李市 54.5000
    沙洋 54.5000
    广华寺 57.5000
    荆门 57.5000
    李市 57.5000
    沙洋 57.5000
    广华寺 58.0000
    荆门 58.0000
    沙洋 58.0000
    广华寺 65.0000
    荆门 65.0000
    李市 65.0000
    沙洋 65.0000
    荆门 66.0000
    沙洋 66.0000
    荆门 81.0000
    沙洋 81.0000
    因为我要按票价排序,所以要加入票价
    我现在想把每个站名各取出一个,怎么改?
      

  7.   

    select fare.station as 站名,max(wholecoach.price) as 最大票价 from wholecoach,fare,station where wholecoach.terminal='荆门' and wholecoach.runline=fare.code and fare.memorial=station.memorial group by fare.station order by max(wholecoach.price)
      

  8.   

    select fare.station as 站名,max(wholecoach.price) as 票价 from wholecoach,fare,station where wholecoach.terminal='荆门' and wholecoach.runline=fare.code and fare.memorial=station.memorial group by fare.station order by wholecoach.price
      

  9.   

    select fare.station as 站名,avg(wholecoach.price) as 平均票价 from wholecoach,fare,station where wholecoach.terminal='荆门' and wholecoach.runline=fare.code and fare.memorial=station.memorial group by fare.station order by avg(wholecoach.price)
      

  10.   

    select fare.station as 站名,min(wholecoach.price) as 票价 from wholecoach,fare,station where wholecoach.terminal='荆门' and wholecoach.runline=fare.code and fare.memorial=station.memorial group by fare.station order by min(wholecoach.price)
      

  11.   

    select max(A.开班日期) as 此站点最近开班日期, A.站名 from (你的那句SQL) as A group by A.站名