SELECT ManagerID AS Manager,COUNT(*) AS Reports FROM Human.Resources.Employee2 WHERE EmployeeID !=5 GROUP BY ManagerID HAVING COUNT(*)>3;having 是聚合以后算的,很棒。where 是聚合以前算的。用FOR XML子句可以输出XML格式。ALL DISTINCT的用法。