我有这两个表,我必须编写这个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 authors.book_id = orders.book_id
GROUP BY authors.author_id;
获得的许多次
答案 0 :(得分:1)
这个怎么样?
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;