我需要一些帮助 问:获得项目总剩余空间最好在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