GROUP BY HAVING,ORDER BY
--HAVING语句与GROUP BY语句联合使用,用来过滤由GROUP BY语句返回的记录集。 --并且HAVING语句的存在弥补了WHERE关键字不能与聚合函数联合使用的不足。 SELECT COUNT(1), SUM([COLUMN_NAME]), MAX([COLUMN_NAME]), MIN([COLUMN_NAME]), [COLUMN_NAME], ... FROM [TABLE_NAME] GROUP BY [COLUMN_NAME] HAVING [COLUMN_NAME] > [SIZE] AND [COLUMN_NAME] = [SIZE] ORDER BY [COLUMN_NAME] [DESC/ASC]; --EG: SELECT COUNT(1), S.SEX, S.U_NUMBER FROM USERS S GROUP BY S.SEX,S.U_NUMBER HAVING S.U_NUMBER > 3 AND S.U_NUMBER = 6 ORDER BY S.U_NUMBER DESC;