Sql 两个一对多表之间的联接
我有这两个表,我必须编写此SQL查询(Microsoft Access):Sql 两个一对多表之间的联接,sql,ms-access,Sql,Ms Access,我有这两个表,我必须编写此SQL查询(Microsoft Access): 写一个查询,显示每一位售出任何书籍的作者的书名(图书编号)和销售量(订购数量) 我尝试过这个查询,但不起作用 SELECT authors.author_id, Count(orders.book_id) AS CountOfbook_id, Sum(orders.quantity_ordered) AS SumOfquantity_ordered FROM authors LEFT JOIN orders ON
- 写一个查询,显示每一位售出任何书籍的作者的书名(图书编号)和销售量(订购数量)
SELECT authors.author_id, Count(orders.book_id) AS CountOfbook_id,
Sum(orders.quantity_ordered) AS SumOfquantity_ordered
FROM authors
LEFT JOIN orders ON authors.book_id = orders.book_id
GROUP BY authors.author_id;
但它不起作用,因为它计算了从客户订单上取下的同一本书的许多倍。这个怎么样
select author,sum(CountOfbook_id), sum(SumOfquantity_ordered)
from (
SELECT authors.author_id as author, Count(orders.book_id) AS CountOfbook_id,
Sum(orders.quantity_ordered) AS SumOfquantity_ordered
FROM authors
LEFT JOIN orders ON authors.book_id = orders.book_id
GROUP BY authors.author_id,authors.book_id;)
group by author;
你试过什么?它产生了什么结果/它与您想要的有什么不同?请阅读并接受答案我编写了我在底部尝试的查询SQL,Microsoft Access我尝试了,但我得到了同一作者两次,请参见:我已修改它