StationID BusID Seq
1 1 1
2 1 2
3 1 3
3 2 1
4 2 2
5 2 3
5 3 1
6 3 2
7 3 1建有3张表,Bus,Station,Bus_Station
上图是Bus_Station表, 现在假设我要查找不经过StationID为 1和7 的BusID,想要得到的结果是BusID为2。
可是不知道该查询语句如何写。求指导
1 1 1
2 1 2
3 1 3
3 2 1
4 2 2
5 2 3
5 3 1
6 3 2
7 3 1建有3张表,Bus,Station,Bus_Station
上图是Bus_Station表, 现在假设我要查找不经过StationID为 1和7 的BusID,想要得到的结果是BusID为2。
可是不知道该查询语句如何写。求指导
from Bus_Station
where StationID not in (1,7) and BUSID=2
where BusID not in (select BusID from Bus_Station where StationID in (1,7))
and BUSID=2;