mysql语句查询,求大牛指导

Jay_M 2012-05-19 05:13:50
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。
可是不知道该查询语句如何写。求指导
...全文
53 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rotel-刘志东 2012-05-20
  • 打赏
  • 举报
回复
select * from Bus_Station
where BusID not in (select BusID from Bus_Station where StationID in (1,7))
and BUSID=2;

rucypli 2012-05-19
  • 打赏
  • 举报
回复
select *
from Bus_Station
where StationID not in (1,7) and BUSID=2
ACMAIN_CHM 2012-05-19
  • 打赏
  • 举报
回复
select * from Bus_Station表 where BusID not in (select BusID from Bus_Station表 where StationID in (1,7));

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧