博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[SQL]LeetCode596. 超过5名学生的课 | Classes More Than 5 Students
阅读量:5370 次
发布时间:2019-06-15

本文共 2256 字,大约阅读时间需要 7 分钟。

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝()
➤GitHub地址:
➤原文地址: 
➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

1 Create table If Not Exists courses (student varchar(255), class varchar(255)) 2 Truncate table courses 3 insert into courses (student, class) values ('A', 'Math') 4 insert into courses (student, class) values ('B', 'English') 5 insert into courses (student, class) values ('C', 'Math') 6 insert into courses (student, class) values ('D', 'Biology') 7 insert into courses (student, class) values ('E', 'Math') 8 insert into courses (student, class) values ('F', 'Computer') 9 insert into courses (student, class) values ('G', 'Math')10 insert into courses (student, class) values ('H', 'Math')11 insert into courses (student, class) values ('I', 'Math')

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.


有一个courses 表 ,有: student (学生) 和 class (课程)。

请列出所有超过或等于5名学生的课。

例如,表:

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

应该输出:

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

Note:

学生在每个课中不应被重复计算。


1465ms

1 # Write your MySQL query statement below2 select class3 from courses group by class having COUNT(DISTINCT student) >= 5

1479ms

1 # Write your MySQL query statement below2 SELECT 3     class4 FROM5     courses6 GROUP BY class7 HAVING COUNT(DISTINCT student)>=5

 

转载于:https://www.cnblogs.com/strengthen/p/10450346.html

你可能感兴趣的文章
MyEclipse部署Jboss出现java.lang.OutOfMemoryError: PermGen space
查看>>
ZOJ 1133
查看>>
alibaba / zeus 安装 图解
查看>>
Planned Delivery Time as Work Days (SCN discussion)
查看>>
Ubuntu:让桌面显示回收站
查看>>
Android上传头像代码,相机,相册,裁剪
查看>>
git 安装体验
查看>>
Oracle 给已创建的表增加自增长列
查看>>
《DSP using MATLAB》Problem 2.17
查看>>
if 循环
查看>>
uva 111 History Grading(lcs)
查看>>
Python学习week2-python介绍与pyenv安装
查看>>
php判断网页是否gzip压缩
查看>>
一个有意思的js实例,你会吗??[原创]
查看>>
sql server中bit字段实现取反操作
查看>>
Part3_lesson2---ARM指令分类学习
查看>>
jQuery拖拽原理实例
查看>>
JavaScript 技巧与高级特性
查看>>
Uva 11729 Commando War
查看>>
增强学习(一) ----- 基本概念
查看>>