SQL Language

GROUP BY 语句

        GROUP BY 语句用于结合合计函数,根据一个或多个列对结果集进行分组(常适用分组统计、合计)

       语法:
       SELECT column_name, aggregate_function(column_name)
       FROM table_name
       [WHERE column_name operator value]
       GROUP BY column_name

       例: 查询每个班的学生数量?
       SELECT classId, count(*) FROM student
       GROUP BY classId

       例: 查询指定班的学生数量?
       SELECT classId, count(*) FROM student
       WHERE classId in('class1','class2','class3')
       GROUP BY classId
posted @ 2014-12-09 17:02  hypo106  阅读(155)  评论(0编辑  收藏  举报