内部连接的 SQL where 子句
Posted
技术标签:
【中文标题】内部连接的 SQL where 子句【英文标题】:SQL where clause on inner joins 【发布时间】:2016-08-17 08:45:24 【问题描述】:我正在使用 pgadminIII (postgreSQL)
我有以下表格: 书, 出版商, 订单行, ShopOrder。
使用以下 SQL:
SELECT
Book.BookID AS "Book ID"
,Book.Title AS "Book title"
,SUM(OrderLine.quantity) AS "Number Ordered"
,ShopOrder.OrderDate AS "Order Date"
FROM (((Book
INNER JOIN OrderLine
ON Book.BookID = OrderLine.BookID)
INNER JOIN Publisher
ON Book.PublisherID = Publisher.PublisherID )
INNER JOIN ShopOrder
ON OrderLine.ShopOrderID = ShopOrder.ShopOrderID)
GROUP BY ShopOrder.OrderDate, Name, Book.BookID
.
我想将它与 (WHERE Publisher.Name = "Smith Smitheson"
) 一起使用
我不知道把它放在哪里,或者如果我做得对,请帮忙?
【问题讨论】:
【参考方案1】:...
INNER JOIN Publisher ON Book.PublisherID = Publisher.PublisherID AND Publisher.Name = 'Smith Smitheson' )
...
或
SELECT Book.BookID AS "Book ID" ,Book.Title AS "Book title"
,SUM(OrderLine.quantity) AS "Number Ordered" ,ShopOrder.OrderDate AS
"Order Date" FROM Book
INNER JOIN OrderLine ON Book.BookID = OrderLine.BookID
INNER JOIN Publisher ON Book.PublisherID = Publisher.PublisherID
INNER JOIN ShopOrder ON OrderLine.ShopOrderID = ShopOrder.ShopOrderID
WHERE Publisher.Name = 'Smith Smitheson'
GROUP BY ShopOrder.OrderDate, Name, Book.BookID
【讨论】:
以上是关于内部连接的 SQL where 子句的主要内容,如果未能解决你的问题,请参考以下文章
如何在 mysqli 准备语句中使用多个内部连接和多个 WHERE 子句? [复制]