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