在我疯掉之前,请你帮帮我。我现在在这方面花了一段时间,并求助于你有帮助的好人。我有一个搜索查询:
SELECT Groups.GroupID,
Groups.GroupName,
( SELECT Sum(SiteRates.SiteMonthlySalesValue)
FROM SiteRates
WHERE InvoiceSites.SiteID = SiteRates.SiteID
) AS SumOfSiteRates,
( SELECT Count(InvoiceSites.SiteID)
FROM InvoiceSites
WHERE SiteRates.SiteID = InvoiceSites.SiteID
) AS CountOfSites
FROM (InvoiceSites
INNER JOIN (Groups
INNER JOIN SitesAndGroups
ON Groups.GroupID = SitesAndGroups.GroupID
) ON InvoiceSites.SiteID = SitesAndGroups.SiteID)
INNER JOIN SiteRates
ON InvoiceSites.SiteID = SiteRates.SiteID
GROUP BY Groups.GroupID
与下表关系
http://m-ls.co.uk/ExtFiles/SQL-Relationship.jpg
如果没有 GROUP BY 条目,我可以获得我想要的条目列表,但它会按 SiteID 向下钻取结果,而我想按 GroupID 进行分组。我知道这是可能的,但缺乏完成此任务的专业知识。
任何帮助将不胜感激。