我需要一些幫助 問:獲得項目總剩餘空間最好在1個查詢剩餘的空間留給項目SQL
Grops, items
Group can contain only MaxAllowed items
Groups table
(ID, MAXAllowerdItems)
Items
(ID, Group_ID, Name)
這是不正確的查詢,但起點
select SUM(g.MaxAllowedItems - count(*)),
from FROM items i, Groups g
where g.ID=i.Group_ID
GROUP BY i.Group_ID
HAVING g.MaxAllowedItems > count(*)
不要忘記從查詢中刪除一個'FROM'並刪除'select SUM(g.MaxAllowedItems - count(*))後的逗號,'... – jerdiggity 2013-04-28 20:06:22