题解 | #确定哪些订单购买了prod_id为BR01的产#
确定哪些订单购买了 prod_id 为 BR01 的产品(二)
https://www.nowcoder.com/practice/999aa31a9a504c60baa088d90d82e64d
联结、等联结、子查询、子查询+等联结、子查询+联结。太傻逼了
-- 等联结,再加上子查询的方式 就是先查order表中的字段,判断ordernum是否在orderutems条件中 # SELECT # o.cust_id, # o.order_date # FROM # OrderItems oi, # Orders o # WHERE # oi.order_num = o.order_num # AND oi.prod_id = 'BR01' # ORDER BY # o.order_date -- 子查询 # SELECT # o.cust_id, # o.order_date # FROM # Orders o # WHERE # o.order_num IN ( SELECT order_num FROM OrderItems WHERE prod_id = 'BR01' ) # ORDER BY # o.order_date -- 子查询+等联结(其实这样写很没劲) # select # o.cust_id, # o.order_date # from # Orders o, # (select order_num from OrderItems where prod_id = 'BR01') t # where # o.order_num = t.order_num # ORDER BY # o.order_date -- 联结语法 # SELECT # o.cust_id, # o.order_date # FROM # OrderItems oi # INNER JOIN Orders o ON oi.order_num = o.order_num # WHERE # oi.prod_id = 'BR01' # ORDER BY # o.order_date -- 子查询+联结(其实这样写很没劲) SELECT o.cust_id, o.order_date FROM Orders o INNER JOIN ( SELECT order_num FROM OrderItems WHERE prod_id = 'BR01' ) t ON o.order_num = t.order_num ORDER BY o.order_date