我有一個名爲Item Item的列ItemID(PK),ItemName,ExpectedSubItems和另一個名爲SubItem與列SubItemID(PK),ItemID(FK),SubItemName的表。SQL的返回行的子項的計數不等於列值
我想返回Item中的所有行,其中SubItems的數量與ExpectedSubItems不同。
我嘗試使用類似: -
Select * From Item
Join SubItem on Item.ItemID = SubItem.ItemID
Where ExpectedSubItems = Count(SubItem.ItemID)
但給我的錯誤: -
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
任何想法從SQL大師的在那裏?
你需要一個GROUP BY在某處有 – 2009-12-14 16:32:29
天哪,這個論壇是快... – 2009-12-14 16:32:57
是的,我相信一些響應者實際上是監控論壇24小時的機器人,並立即回答任何問題:) – 2009-12-14 16:35:20