mysql一秒最多写多少次_Mysql的两种“超过多少次”写法(力扣596)
发布日期:2021-06-24 07:19:28 浏览次数:4 分类:技术文章

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

题目:

有一个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:

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

答案1:

select a.class from

(select count(distinct student) as num, class from courses group by class) a

where a.num >= 5

答案2:

select class from courses group by class having count(class) > 4

对比一下效率是一样的:

[SQL] SELECT age from test_user GROUP BY age having count(age)>1;

受影响的行: 0

时间: 0.001s

[SQL]

select a.age from

(select count(age) as num, age from test_user group by age) a

where a.num >= 2;

受影响的行: 0

时间: 0.001s

转载地址:https://blog.csdn.net/weixin_30975527/article/details/113415631 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:mysql el函数_MySQL中的常用函数
下一篇:phpmyadmin管理mysql_LAMP实验二:使用phpMyAdmin管理MySQL

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月19日 04时27分51秒