2
我有一个表的设计,像这样查找外键匹配多行值
person_id | department
1 | a
1 | b
2 | a
2 | c
3 | b
3 | a
,并希望有一个查询返回所有属于部门A和B为person_id的的。我想这将是沿线
select person_id from table group by person_id having ....
但不能完全弄清楚。有谁知道我该怎么做?
编辑:我想我能做到以下几点。但它看起来像一个黑客。
select person_id from table where department='A' or department='B'
group by person_id having count(1) > 1