Consider the following rows that is returned from a query:
name number
foo 1
foo 9
foo 10
foo 11
bar 12
bar 13
dumb 14
Run Code Online (Sandbox Code Playgroud)
How do I select the name where the number of such name is never under 10, and appear at least twice so this case, i wanted it to return
name
bar
Run Code Online (Sandbox Code Playgroud)
What I have tried:
select name from my_table
where number >= 10 #<--Problem
group by name
having count(*) >=2
Run Code Online (Sandbox Code Playgroud)
This works partially because it was not able to filter out foo. The problem of this query is that it will be able to filter out foo 1 and foo 9 but foo 10 and foo 11 will be returned.
select name from my_table
group by name
having count(*) >=2 and min(number) >= 10
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17 次 |
| 最近记录: |