sql方面问题 请教各位高手

来源:百度知道 编辑:UC知道 时间:2024/06/18 06:45:53
我在网上查到的公交查询语言
1.直达
select line_id from
(select line_id from linestops where stop_id = id1) A,
(select line_id from linestops where stop_id = id2) B
where A.line_id = B.line_id
2.换乘
select stop_id from
(
select distinct stop_id from linestops where line_id in
(select line_id from linestops where stop_id = id1)
)A,
(
select distinct stop_id from linestops where line_id in
(select line_id from linestops where stop_id = id1)
)B
where A.stop_id = B.stop_id
3.二次换乘
select line_id from
(select distinct line_id from linestops where stop_id in 【A】) C,
(select distinct line_id from linestops where stop_id in 【B】) D
where C.line_id = D.line_id

其中【A】是

(select distinct stop_id from linestops where line_id in
(select line_id from linestops where stop_id = id1))
其中【B】是

(select distinct stop_id from linestops where line_id in

估计mysql不支持这么多层的嵌套查询吧

做个测试:
select line_id from
(select distinct line_id from linestops where stop_id in 【具体某个ID】) C,
(select distinct line_id from linestops where stop_id in 【具体某个ID】) D
where C.line_id = D.line_id
看下是否能执行

然后执行:
(select distinct stop_id from linestops where line_id in
(select line_id from linestops where stop_id = id1))
看下是否能执行

如果两个都能执行,放在一起不能执行就说明MYSQL用不了这种语法,只要想其他的方式了,实在就只能写游标了