【LeetCode】596、Classes More Than 5 Students

来源:互联网 发布:手机底部导航栏源码 编辑:程序博客网 时间:2024/06/05 06:36

题目要求:

There is a table courses with columns: student and class

Please list out all classes which have more than or equal to 5 students.

解答:COUNT与 DISTINCT组合使用,满足The students should not be counted duplicate in each course.的要求。也可以用组合查询。

COUNT 语法:http://www.w3school.com.cn/sql/sql_func_count.asp

SELECT class FROM coursesGROUP BY classHAVING COUNT(DISTINCT(student)) >= 5

原创粉丝点击