Table1Orders
OrderID(pk)
ISBN(fk)
ProductID(fk)
OrderDate
Total
Table2Books
ISBN(pk)
AuthorID(fk)
PublisherID(fk)
Title
PubDate
Table3Authors
AuthorID(pk)
AuthorName
AuthorAddress
AuthorPhone
Table4Publishers
PublisherID(pk)
PublisherName
PubAddress
PubPhone
我如何找到哪个发布商销售的图书最多?
我需要在INNER JOIN
和Orders
详细信息之间Book
吗?
我如何对返回的数据进行排序,以便将publisher
与ISBN
相关联并且大多数已售出?
答案 0 :(得分:1)
如果您将图书和图书的订单加入发布商,以便将发布商订购链接作为表格,则根据列名称,然后按发布商,按发布商分组查询并计算行数:
select p.PublisherName, count(*) as BooksSold
from Table1Orders o
inner join Table2Books b on o.ISBN = b.ISBN
inner join Table4Publishers p on b.PublisherID = p.PublisherID
group by p.PublisherName
order by count(*) desc