小蜜锋 - 云代码空间
—— 技术宅拯救世界!
SELECT t1.Department AS depId, t2.Name AS Department, t3.Name AS Unit, COUNT(t1.Department) AS depSum, ROUND(AVG(t1.Percent), 2) AS percentAvg, COUNT(IF(t1.Percent>=100,true,null)) AS finishCount FROM task AS t1, department AS t2, unit AS t3 WHERE t1.Department = t2.Id AND t2.Unit = t3.Id AND t1.Department NOT IN (3,4,5,6) GROUP BY t1.Department ORDER BY percentAvg DESC LIMIT 10