2012-08-06 85 views
-3

我一直有一個錯誤SQL服務器:語法錯誤

附近有語法錯誤關鍵字 '選擇'
錯誤syntac附近 ')'

(SELECT TOP 5 t2.ItemID, SUM(t2.Quantity) 
FROM Orders as t1 
as Quantity FROM t2.ItemID in 

(SELECT ItemID FROM Orders as t1 INNER JOIN BasketItems as t2 on t2.BasketID = t1.BasketID 

WHERE t1.OrderStatusID = 3 AND t1.OrderDate BETWEEN '" + LastWeekDate + "' AND '" + TomorrowsdaysDate + "') 

GROUP BY t2.ItemID ORDER BY Quantity desc"); 
+0

安置自己的BasketItems,訂單數據結構 – podiluska 2012-08-06 10:18:30

回答

1

你錯過了FROM部分在外部SELECT語句(第2行)

你在那裏有一個WHERE條件

而且我不認爲你需要爲這個

子查詢試試這個

(' SELECT TOP 5 t2.ItemID, SUM(t2.Quantity) as Quantity 
    FROM Orders as t1 
     INNER JOIN BasketItems as t2 on t2.BasketID = t1.BasketID 
    WHERE t1.OrderStatusID = 3 
    AND t1.OrderDate BETWEEN '" + LastWeekDate + "' AND '" + TomorrowsdaysDate + "' 
    GROUP BY t2.ItemID ORDER BY 2 desc 
'); 
相關問題