mysql - 选择某一行,其中某些列从未使某些条件失败

标签 mysql sql

考虑从查询返回的以下行:

name  number
foo     1
foo     9
foo     10
foo     11
bar     12
bar     13
dumb    14

我如何选择这样的名称的数量永远不会低于 10,并且至少出现两次的名称,所以在这种情况下,我希望它返回

name
bar

我尝试过的:

select name from my_table
where number >= 10 #<--Problem
group by name
having count(*) >=2 

部分原因是它无法过滤掉 foo。此查询的问题在于它将能够过滤掉 foo 1foo 9foo 10foo 11 将被返回。

最佳答案

select name from my_table 
group by name 
having count(*) >=2 and min(number) >= 10

关于mysql - 选择某一行,其中某些列从未使某些条件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55995822/

相关文章:

php - 防止 Eloquent 查询中的模型水合作用

MySQL count(DISTINCT) 非常慢 - 子查询更好?

java - 如何在 NetBeans 中正确连接 MySQL 数据库?

php - 根据用户输入循环将数据附加到sql数据库

sql - Oracle 中的部分索引还是完整索引?

sql - 甲骨文 : Foreign Key Error : Unknown Command

mysql - #1111 SQL 中 Group 函数的使用无效 : Concept?

php - 网站/数据库文本编码问题

sql - 向 Azure 数据工厂中的表添加新列

sql - 按时间戳日期分组