« 正则表达式中的特殊字符 | 首页 | 港台大陆明星出场费报价表(参考价) »

列车查询时的数据库查询问题

在做列车时刻表时遇到的问题
表名: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 秒

发表评论

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.2