如何使用子查询重现这一点?

时间:2017-10-09 17:41:11

标签: sql subquery

我刚刚开始学习SQL,并且已经负责使用子查询重新创建它,但是我已经搜索了一下,但仍然无法理解如何做到这一点。任何帮助将不胜感激:)

SELECT ORDER_NUMB, ORDER_DATE FROM BRIAN.ORDERS
INNER JOIN BRIAN.CUSTOMERS 
ON BRIAN.ORDERS.CUSTOMER_NUMB=BRIAN.CUSTOMERS.CUSTOMER_NUMB
WHERE CUSTOMER_FIRST_NAME = 'Peter' 
AND CUSTOMER_LAST_NAME = 'Johnson';

1 个答案:

答案 0 :(得分:1)

您应该在子查询中选择Peter Johnson客户并对其进行过滤。

SELECT ORDER_NUMB
    , ORDER_DATE 
FROM BRIAN.ORDERS
WHERE BRIAN.ORDERS.CUSTOMER_NUMB IN (SELECT BRIAN.CUSTOMERS.CUSTOMER_NUMB
                                FROM BRIAN.CUSTOMERS
                                WHERE CUSTOMER_FIRST_NAME = 'Peter' 
                                AND CUSTOMER_LAST_NAME = 'Johnson')