不好意思,没注意,那用这个兜弯子的语句看看应该可以达到你的目的: select a.路线 from 表 a,表 b where a.路线=b.路线 and a.经过地点<b.经过地点 and co ncat(a.经过地点,b.经过地点)='001002';
这种句式在多表查询的时候可以帮我解决问题,但是我现在是单表啊~~~~ 我的查询写成带in的SQL应该是: select * from a where (a.place = '001') and a.line in (select a.line from a where a.place = '002')可以把这种子查询转换为关联查询吗?
select a.路线 from 表 a,表 b where a.路线=b.路线 and a.经过地点<b.经过地点 and co ncat(a.经过地点,b.经过地点)='001002';这个本来就是在对一个表做查询啊,不过起了两个别名
对啊,表可以自己join自己的。 select 路线 from table1 t1 left join table1 t2 on t1.路线=t2.路线 where t1.经过地点='001' and t2.经过地点='002'
换个思路如何 符合条件 经过地点='001' or 经过地点='002' 的记录数为2的 路线 都是你想要的,对不对这样 select 路线 from t where 经过地点='001' or 经过地点='002' group by 路线 having count(路线)=2
select a.路线 from 表 a,表 b where a.路线=b.路线 and a.经过地点<b.经过地点 and co
ncat(a.经过地点,b.经过地点)='001002';
我的查询写成带in的SQL应该是:
select * from a where (a.place = '001') and a.line in (select a.line from a where a.place = '002')可以把这种子查询转换为关联查询吗?
ncat(a.经过地点,b.经过地点)='001002';这个本来就是在对一个表做查询啊,不过起了两个别名
select 路线
from table1 t1
left join table1 t2 on t1.路线=t2.路线
where t1.经过地点='001' and
t2.经过地点='002'
符合条件 经过地点='001' or 经过地点='002'
的记录数为2的 路线 都是你想要的,对不对这样
select 路线 from t where 经过地点='001' or 经过地点='002' group by 路线 having count(路线)=2