- 列出与艺术家,订单日期和发货日期一起出售的所有商品
SELECT title, artist, order_date, ship_date
FROM items,orders,orderline
WHERE orders.order_id = orderline.order_id
AND items.item_id = orderline.item_id;
我尝试了自己的查询,我得到了以下结果
Under the Sun, Donald Arley, 11/15/2013, 11/20/2013
Under the Sun, Donald Arley, 12/20/2013, 12/22/2013
Under the Sun, Donald Arley, 1/18/2014, 1/23/2014
Dark Lady, Keith Morris, 1/31/2014, 2/4/2014
Dark Lady, Keith Morris, 3/10/2014, 3/15/2014
Dark Lady, Keith Morris, 3/14/2014, 3/19/2014
Dark Lady, Keith Morris, 11/15/2013, 11/20/2013
Happy Days, Andrea Reid, 2/27/2014, 3/2/2014
Happy Days, Andrea Reid, 10/30/2013, 11/3/2013
Happy Days, Andrea Reid, 12/18/2013, 12/22/2013
The Hunt, Walter Alford, 1/31/2014, 2/4/2014
The Hunt, Walter Alford, 3/10/2014, 3/15/2014
等...............
答案 0 :(得分:2)
这看起来像是一个通用的家庭作业问题。
我建议您熟悉此页面和网站http://use-the-index-luke.com/sql/join。
解决方案:
将您的陈述更改为:
SELECT
items.title, items.artist, orders.order_date, orders.ship_date
FROM
items
JOIN
orderline ON orderline.item_id = items.item_id
JOIN
orders ON orders.order_id = orderline.order_id