There is a table courses with columns: student and class

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

For example, the table:

+---------+------------+
| student | class |
+---------+------------+
| A | Math |
| B | English |
| C | Math |
| D | Biology |
| E | Math |
| F | Computer |
| G | Math |
| H | Math |
| I | Math |
+---------+------------+

Should output:

+---------+
| class |
+---------+
| Math |
+---------+

Note:
The students should not be counted duplicate in each course.

Code     #用distinct是因为有可能有学生多次选了该门课

SELECT class FROM courses GROUP BY class HAVING COUNT(DISTINCT student) >= 5 

[LeetCode] 596. Classes More Than 5 Students_Easy tag:SQL的更多相关文章

  1. LeetCode - 596. Classes More Than 5 Students

    There is a table courses with columns: student and class Please list out all classes which have more ...

  2. LeetCode 596. Classes More Than 5 Students (超过5名学生的课)

    题目标签: 题目给了我们 courses 表格,让我们找到 一个有至少5名学生的班级. 利用group by 把班级分类,在用Having count 来判断是否有5名,注意这里还需要用 distin ...

  3. [LeetCode] 613. Shortest Distance in a Line_Easy tag: SQL

    Table point holds the x coordinate of some points on x-axis in a plane, which are all integers. Writ ...

  4. [LeetCode] 33. Search in Rotated Sorted Array_Medium tag: Binary Search

    Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...

  5. [LeetCode] 364. Nested List Weight Sum II_Medium tag:DFS

    Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...

  6. [LeetCode] 849. Maximize Distance to Closest Person_Easy tag: BFS

    In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is emp ...

  7. [LeetCode] 298. Binary Tree Longest Consecutive Sequence_Medium tag: DFS recursive

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  8. [LeetCode] 787. Cheapest Flights Within K Stops_Medium tag: Dynamic Programming, BFS, Heap

    There are n cities connected by m flights. Each fight starts from city u and arrives at v with a pri ...

  9. [LeetCode] 821. Shortest Distance to a Character_Easy tag: BFS

    Given a string S and a character C, return an array of integers representing the shortest distance f ...

随机推荐

  1. 使用Zabbix监控RabbitMQ消息队列

    参考文档:http://blog.51cto.com/270142877/1937241 本项目脚本下载地址:https://github.com/jasonmcintosh/rabbitmq-zab ...

  2. tsm 带库 磁带

    磁带和存储池设置 新装入带库的磁带,需执行格式化命令方可使用,而存储池采用手工定义方式加入磁带,所以checkin状态设置为private,而不使用scratch磁带自动定义方式. label lib ...

  3. db2 reorg(转)

    DB2 reorg RUNSTATS: db2 connect to rmdb11 user rmadmin using rmadmin 对所有用户表执行runstats(reorgchk加updat ...

  4. Cross-origin plugin content from must have a visible size larger than 400 x 300 pixels, or it will be blocked. Invisible content is always blocked.

    Cross-origin plugin content from  must have a visible size larger than 400 x 300 pixels, or it will ...

  5. {Django基础十之Form和ModelForm组件}一 Form介绍 二 Form常用字段和插件 三 From所有内置字段 四 字段校验 五 Hook钩子方法 六 进阶补充 七 ModelForm

    Django基础十之Form和ModelForm组件 本节目录 一 Form介绍 二 Form常用字段和插件 三 From所有内置字段 四 字段校验 五 Hook钩子方法 六 进阶补充 七 Model ...

  6. [development][security][suricata] suricata 使用与调研

    0: OISF:https://oisf.net/ 1: suricata是什么 https://suricata-ids.org/ 2:安装 https://redmine.openinfosecf ...

  7. [administrative][lvm] lvm 分区修改

    默认安装的CentOS6.3操作系统,使用lvm分区.root挂载了50G,home挂载了1.5T. 由于需求要求,现在需要把home的1.5T全部移动到root下. 使用archiso启动,查看lv ...

  8. TZOJ:玛祖游戏

    描述 玛祖是一款非常经典的游戏,游戏的角色是一只青蛙,青蛙每次可以吐出一颗珠子,如果将珠子吐到场景中相同颜色的珠子旁边(称为击中),当三个或者三个以上的同颜色珠子在一起的时候便可以消掉,如果消掉后还有 ...

  9. 10.7-uC/OS-III内部任务(定时器任务 OS_TmrTask())

    {这节所说的定时器都是软件定时器} 1.uC/OS-III为用户提供了定时器任务,相应代码在OS_TMR.C中.定时器任务是可选的,通过将OS_CFG.H中的OS_CFG_TMR_EN设置为1使能.当 ...

  10. private static final Logger logger= LoggerFactory.getLogger(WhMainBusi.class);

    LoggerFactory.getLogger(WhMainBusi.class):指定类初始化日志对象,在日志输出的时候,将会打印日志信息所在的类.如: logger.info("日志信息 ...