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. DataGridView实时提交

    自定义了一个工具,根据DataGridView中的值进行其他操作.在DataGridView中修改了值,直接做其他操作时, 结果DataGridview中的值显示为a,则操作的属性却是没修改后的值b. ...

  2. OpenGL开发学习指南二(glfw+glad)

    版权声明:本文为博主原创文章,未经博主允许不得转载.blog.liujunliang.com.cn https://blog.csdn.net/qq_33747722/article/details/ ...

  3. Apache Sharding-Sphere

    Sharding-Sphere 正式步入 Apache 基金会孵化器 - 开源中国 https://www.oschina.net/news/101691/sharding-sphere-enter- ...

  4. data-original

    <img class="lazy" style="display: inline;" alt="开光纯铜牛摆件" src=" ...

  5. Shell脚本交互之:自动输入密码

    Shell脚本交互之:自动输入密码 2016年04月09日 19:41:26 zhangjikuan 阅读数:58208 标签: Shell交互自动输入密码expect重定向管道 更多 个人分类: A ...

  6. 重写toString()

    重写Object的toString()之前,得到的结果是  类型 @ 内存地址 demo: package cn.sasa.demo1; public class Test { public stat ...

  7. phpstudy + dvws

    下载apache+mysql+php 的服务组件 phpstudy phpstudy 下载地址 https://www.baidu.com/link?url=EN5Br6PK-Gboaf905Jjt0 ...

  8. java开发中乱码的解决

    总结一下,在JavaWeb中针对各种情况处理中文乱码的方法. 首先我们看下,一个请求响应的流程 浏览器------------------>Servlet容器---------------> ...

  9. 【UNIX网络编程(三)】TCP客户/server程序演示样例

    上一节给出了TCP网络编程的函数.这一节使用那些基本函数编写一个完毕的TCP客户/server程序演示样例. 该样例运行的过程例如以下: 1.客户从标准输入读入一行文本,并写给server. 2.se ...

  10. 20180323 DataTable增加DataRow方式优化

    1. 我开始开发程序时,很多问题考虑不周期,不断的在改进中 最开始我的写法,创建一个DataTable 的Columns,采用语句 dt2.Columns.Add("ID"); 这 ...