我试图从mysql数据库中获取用户,如果他们已经创建了一个注释,weather type = 'cloud','rain','clear'而不是那些错过了这三个中的一个.
例如.
id user_id weather_type
1 12 cloud
2 12 rain
3 12 clear
4 14 rain
5 15 clear
Run Code Online (Sandbox Code Playgroud)
现在这里只有用户12创建了所有三个音符,weather_type所以只有12个应该被提取而不是14和15.
使用group by和having:
select user_id
from mytable
where weather_type in ('cloud','rain','clear')
group by user_id
having count(distinct weather_type) = 3
Run Code Online (Sandbox Code Playgroud)