2

我在蜂巢中有以下数据:

userid cityid
1      15
2      15
1      7
3      15
2      8
3      9
3      7

而且我只想保留具有 cityid 15 和 cityid 7 的用户 ID(在我的示例中,它将是用户 ID 1 和 3)。我试过:

select userid from table where cityid = 15 and userid in (select userid from table where cityid = 7);

但是对于蜂巢,它不起作用。有人可以帮忙吗?

谢谢!

4

3 回答 3

2

好的,我找到了方法:

select a.userid from (select userid from table where cityid = 15) a join (select userid from table where cityid = 7) b on a.userid = b.userid;
于 2012-11-09T11:12:22.760 回答
1

尝试避免自加入

SELECT  userid
FROM
 ( SELECT userid, collect_set( cityid) as cities
   FROM table 
   GROUP BY userid 
 )
WHERE array_contains( cities, 7 )
AND array_contains( cities, 15 );
于 2014-03-31T17:08:47.683 回答
0
SELECT DISTINCT userid FROM table_name WHERE cityid == 15 OR cityid == 7;
于 2012-11-12T12:22:44.150 回答