日期:2014-05-18 浏览次数:20510 次
SELECT DISTINCT a.Project_Yjdw as 移交单位, COUNT(a.Project_Id) AS 工程数量, SUM(a.Project_Mj) AS 面积, SUM(b.Docu_PageCount) AS 大图数量 FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro GROUP BY a.Project_Id, a.Project_Yjdw, a.Project_Mj, b.Docu_PageCount
SELECT DISTINCT a.Project_Yjdw as 移交单位, COUNT(a.Project_Id) AS 工程数量, SUM(a.Project_Mj) AS 面积, SUM(b.Docu_PageCount) AS 大图数量 FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro where b.Docu_PageCount=2 GROUP BY a.Project_Id, a.Project_Yjdw, a.Project_Mj, b.Docu_PageCount
------解决方案--------------------
SELECT DISTINCT a.Project_Yjdw as 移交单位, COUNT(a.Project_Id) AS 工程数量, SUM(a.Project_Mj) AS 面积, SUM(b.Docu_PageCount) AS 大图数量 FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro GROUP BY a.Project_Id, a.Project_Yjdw, a.Project_Mj, b.Docu_PageCount having b.Docu_PageCount=2
------解决方案--------------------
那你先把子查询写出来,再把子查询当做表去关联
------解决方案--------------------
加個HAVING SUM(b.Docu_PageCount)=2
------解决方案--------------------
--若是b.Docu_PageCount=2,将其加在WHERE后 SELECT DISTINCT a.Project_Yjdw as 移交单位, COUNT(a.Project_Id) AS 工程数量, SUM(a.Project_Mj) AS 面积, SUM(b.Docu_PageCount) AS 大图数量 FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro where b.Docu_PageCount=2 GROUP BY a.Project_Id, a.Project_Yjdw, a.Project_Mj, b.Docu_PageCount --若是sum(b.Docu_PageCount)=2,将其加在having后 SELECT DISTINCT a.Project_Yjdw as 移交单位, COUNT(a.Project_Id) AS 工程数量, SUM(a.Project_Mj) AS 面积, SUM(b.Docu_PageCount) AS 大图数量 FROM UDP_Project as a INNER JOIN UDP_Document as b ON a.Project_Id = b.Docu_ForPro GROUP BY a.Project_Id, a.Project_Yjdw, a.Project_Mj, b.Docu_PageCount having sum(b.Docu_PageCount)=2