当我执行下面的查询时,它会抛出错误说:语法错误在“as”或附近。
我们如何解决这个问题?
还有其他方法吗?
(select * from my_table1 where status='6') as a
left JOIN
(select * from my_table1 where status='1') as b
ON (a.application_id = b.application_id)
通过使用子查询中的选择尝试如下所示
select a.* from (select * from my_table1 where status='6') as a
left JOIN
(select * from my_table1 where status='1') as b
ON a.application_id = b.application_id
你错过了最初的select * from
条款。而且,不需要子查询;你只需要小心条件放置。
select *
from my_table1 a
left join my_table1 b on b.status='1' and
b.application_id = a.application_id
where a.status='6'
您已从子查询中选择所有值以加入它们:
select a.* from (select * from my_table1 where status='6') as a
left JOIN
select b.* from (select * from my_table1 where status='1') as b
ON (a.application_id = b.application_id)
select * from my_table1 as A
LEFT JOIN my_table1 as B
ON (A.application_id = A.application_id)
WHERE A.status='6' AND B.status='1'