列车查询时的数据库查询问题
在做列车时刻表时遇到的问题
表名:train_lines_part
字段:
line_id 列车车次
station_id 站台ID
。。。。其他略
想查询经过站台2和站台4的所有列车
方法一:
SELECT * , count( * ) AS num FROM `train_lines_part` WHERE station_id =2 OR station_id =4 GROUP BY line_id HAVING num =2
方法二:
select a.line_id from train_lines_part a,train_lines_part b where a.station_id=2 and b.station_id=4 and a.line_id=b.line_id
方法三:
SELECT * FROM (select * from train_lines_part where station_id=2) as from_station where station_id=4
方法一查询花费 0.0008 秒
方法二查询花费 0.0013 秒
方法三查询花费 0.0008 秒
