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. B - 考试排名

    C++编程考试使用的实时提交系统,具有即时获得成绩排名的特点.它的功能是怎么实现的呢? 我们做好了题目的解答,提交之后,要么"AC",要么错误,不管怎样错法,总是给你记上一笔,表明 ...

  2. C语言复制图片文件

    以下代码将文件一的图片复制到文件二中 #include<stdio.h> #include<stdlib.h> int main() { char ch; char fname ...

  3. 编译openssl失败(SLES11.3), undefined reference to `OPENSSL_cpuid_setup'

    https://stackoverflow.com/questions/11381514/undefined-reference-when-compiling-openssl I ran into t ...

  4. 一劳永逸:域名支持通配符,ASP.NET Core中配置CORS

    ASP.NET Core 内置了对 CORS 的支持,使用很简单,只需先在 Startup 的 ConfigureServices() 中添加 CORS 策略: public void Configu ...

  5. python基础①

    一.    Python 命名规范: 1, 变量量由字⺟母, 数字,下划线搭配组合⽽而成 2, 不不可以⽤用数字开头,更更不不能是全数字    3,不能是pythond的关键字, 这些符号和字⺟母已经 ...

  6. [No0000C7]windows 10桌面切换快捷键,win10

    windows 10桌面切换快捷键:Ctrl+Win+←/→ 切换窗口:Alt+Tab(不是新的,但任务切换界面改进)任务视图:Win+Tab(松开键盘界面不会消失)创建新的虚拟桌面:Win+Ctrl ...

  7. Oracle DBLINK 简单使用

    oracle在进行跨库访问时,可以通过创建dblink实现,今天就简单的介绍下如果创建dblink,以及通过dblink完成插入.修改.删除等操作 首先了解下环境:在tnsnames.ora中配置两个 ...

  8. 2016年蓝桥杯省赛A组c++第7题(图论)

    /* 有12张连在一起的12生肖的邮票,规格是3*4,即: 1111 1111 1111 现在你要从中剪下5张来,要求必须是连着的.(仅仅连接一个角不算相连) */ /* 思路: 先将所有五个一组的情 ...

  9. Scaleform 4.3 (1)

    //可变参数传输 GFxValue args[3], result; args[0].SetNumber(i); args[1].SetString("test"); args[2 ...

  10. ms sql server读取xml文件存储过程-sp_xml_preparedocument

    最近要在存储过程中读取xml中节点的值,然后进行sql操作: 要使用到的系统存储过程如下:sp_xml_preparedocument create procedure [dbo].[pro_Test ...