SQL语句检索问题

来源:百度知道 编辑:UC知道 时间:2024/05/29 18:43:30
使用sql语句对
bus_info(车号bus_id,起点站start_location,终点站end_location,票价price)
bus_station(车号bus_id,站台号station_id)
station_info(站台号station_id,站台名station)
这3张表检索:
查询从中关村(station_info中的某站)到白石桥(station_info中的某站)能坐的所有车。
能写个select语句么?我写的有问题。

如果不考虑转车,那么找出带这两站的车就行了
select b.bus_id
from bus_station b inner join station_info s on b.station_id=s.station_id
where s.station in ('中关村','白石桥')
group by b.bus_id having count(*)=2

考虑转车的话,光sql不行,得写存储过程了,而且这三个表也不够……

同意楼上的看发,像这种就最好用存储过程来控制