在下面的查詢中,我試圖做一個快速彙總表來顯示一些信息。使用where子句是爲了從數據庫中找到與該發佈者相關的信息。在查看其他定義一個小時左右後,我看不清楚我的錯在哪裏。SQL where子句什麼都不返回
對不起,這可能是一件很簡單的事情,但是下面的查詢有什麼明顯的錯誤。
SELECT Publisher.Name AS "Publisher Name",
Book.Title AS "Book Title",
ShopOrder.OrderDate AS "Order Date",
OrderLine.Quantity AS "Order Quantity",
(SUM(Quantity*UnitSellingPrice)) AS "Total Value"
FROM ShopOrder
INNER JOIN OrderLine
ON ShopOrder.ShopOrderID=OrderLine.ShopOrderID
INNER JOIN Book
ON OrderLine.BookID=Book.BookID
INNER JOIN Publisher
ON Publisher.PublisherID=Book.PublisherID
WHERE Publisher.Name='Oxford'
GROUP BY ShopOrder.ShopOrderID,
Publisher.PublisherID,
Book.BookID,
OrderLine.Quantity
ORDER BY ShopOrder.OrderDate;
非常感謝任何人的幫助!
編輯: 相關表DEFS
CREATE TABLE Publisher
(
PublisherID INTEGER,
Name VARCHAR(50),
PRIMARY KEY(PublisherID)
);
CREATE TABLE Book
(
BookID INTEGER,
Title VARCHAR(50),
Price DECIMAL (10, 2),
CategoryID INTEGER REFERENCES Category(CategoryID),
PublisherID INTEGER REFERENCES Publisher(PublisherID),
PRIMARY KEY(BookID)
);
CREATE TABLE ShopOrder
(
ShopOrderID INTEGER,
OrderDate DATE,
ShopID INTEGER REFERENCES Shop(ShopID),
SalesRepID INTEGER REFERENCES SalesRep(SalesRepID),
PRIMARY KEY(ShopOrderID)
);
CREATE TABLE OrderLine
(
ShopOrderID INTEGER REFERENCES ShopOrder(ShopOrderID) ON DELETE CASCADE,
BookID INTEGER REFERENCES Book(BookID),
Quantity INTEGER,
UnitSellingPrice DECIMAL (10,2)
);
做的所有連接表都有記錄的數據,其中'Publisher.Name ='Oxford''?從「Publisher」開始,並加入其他表以查看斷開連接的位置。 –
@ d-stanley我是一個SQL noob,所以我不完全確定你的意思。我真的很討厭問這麼愚蠢的問題,因爲我可能是愚蠢的,只是在竊聽你。你能否更詳細地解釋。如果不是不用擔心:) – RyanH
只是爲了測試上述評論,將'INNER JOIN Publisher'改爲'RIGHT JOIN Publisher' –