我希望得到一些建议.我需要弄清楚有多少项目没有100%的合作伙伴分配.
一个项目可以有很多合作伙伴.
项目和合作伙伴表由ProjectID
.
我需要选择项目ID,项目名称FROM项目,其中partner_%!= 100%.
所以我在思考
SELECT project id, project name, SUM (partner_%) as [Project Partner Total] FROM Project Table LEFT JOIN [partner table] ON project.projectID = partner.projectID
我上面的工作可以吗?(这是SQL Server 2014).
如果我理解正确,你需要一个group by
和一个having
条款:
SELECT project id, project name, SUM(partner_%) as [Project Partner Total] FROM Project Table LEFT JOIN [partner table] ON project.projectID = partner.projectID GROUP BY project id, project name HAVING SUM(partner_%) <> 100;