mysql 嵌套查询
selecttrain_no,a.sequ_nofrom,b.sequ_notofrom(select*fromaawherest_name="xxx")asa,(sel...
select
train_no,a.sequ_no from,b.sequ_no to
from
(select * from aa where st_name= "xxx" ) as a ,
(select * from aa where st_name= "xx") as b
where
a.train_no =b.train_no and a.sequ_no<b.sequ_no;
当我这样写时,报错,请问是什么原因呢? 错误位置始终在 第二行到 第四行 这里 展开
train_no,a.sequ_no from,b.sequ_no to
from
(select * from aa where st_name= "xxx" ) as a ,
(select * from aa where st_name= "xx") as b
where
a.train_no =b.train_no and a.sequ_no<b.sequ_no;
当我这样写时,报错,请问是什么原因呢? 错误位置始终在 第二行到 第四行 这里 展开
1个回答
展开全部
你的sql语句中 的 from 和 to 与sql保留关键词 有冲突。
select
a.train_no, a.sequ_no t_from , b.sequ_no t_to
from
(select * from aa where st_name= "xxx" ) as a ,
(select * from aa where st_name= "xx") as b
where
a.train_no = b.train_no and a.sequ_no<b.sequ_no;
或者
select
a.train_no, a.sequ_no as `from` , b.sequ_no as `to`
from
(select * from aa where st_name= "xxx" ) a inner join
(select * from aa where st_name= "xx") b on a.train_no =b.train_no
where a.sequ_no<b.sequ_no;
select
a.train_no, a.sequ_no t_from , b.sequ_no t_to
from
(select * from aa where st_name= "xxx" ) as a ,
(select * from aa where st_name= "xx") as b
where
a.train_no = b.train_no and a.sequ_no<b.sequ_no;
或者
select
a.train_no, a.sequ_no as `from` , b.sequ_no as `to`
from
(select * from aa where st_name= "xxx" ) a inner join
(select * from aa where st_name= "xx") b on a.train_no =b.train_no
where a.sequ_no<b.sequ_no;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询