假如有多条数据,有的user 只有一个国家,但有的user虽然一条数据只包含一个国家,但是多条数据包含多个国家值,如何排除掉这样的user?
-- 外部查询获得分组数量为1的用户数据
select user from (
-- 子查询获得按用户分组的数据
select user,count(0) c from table_x t group by user
) t2 where t2.c=1;
对 count(country_id) 之类的进行条件过滤不行么?
对user进行分组,取每组count为1的记录
having count(distinct country_id) = 1
筛选一下