我似乎有一个问题,将我的3层子查询折叠成一个join语句。这是代码:
Select pid
from orders
where aid in (
select aid
from orders
WHERE cid IN (
select cid
from customers
where city = 'Kyoto'
)
);
编辑:我试图显示通过在京都为客户至少订购一次订单的代理商订购的产品的in。
发布于 2016-10-04 19:42:41
试试这个:
Select o.pid
from orders o
inner join orders oo on oo.aid = o.aid
inner join customers c on c.cid = oo.cid and c.city = 'Kyoto'
我认为别名(o、oo和c)是必要的,以使其按预期工作。
发布于 2016-10-04 19:44:23
为什么您要多次从订单表中选择,而且我认为您的代理和产品表在这里没有用。
SELECT orders.pid
FROM ORDERS orders
INNER JOIN CUSTOMERS customers ON customers.cid = orders.cid
AND customers.city = 'Kyoto'
发布于 2016-10-04 19:49:08
select A.pid
from orders as A
INNER jOIN
Orders as B
on A.aid=B.aid
INNER JOIN
customers as C
on B.cid=C.cid
where C.city = 'Kyoto'
https://stackoverflow.com/questions/39865029
复制相似问题