如果我有5个表,如果我想要在单个列中查找出现在5个表中至少2个中的元素,我应该使用什么连接函数?即:只丢弃那些出现在单个表中的元素。
如果我想在至少3/5的表中找到公共元素,代码会相似吗?
(我正在使用MS Access)
谢谢!
发布于 2013-07-18 09:40:58
我不是100%肯定我理解你的问题,但我认为你可以使用UNION ALL:
select yourcol
from (
select distinct yourcol from t1
union all
select distinct yourcol from t2
union all
select distinct yourcol from t3
union all
select distinct yourcol from t4
union all
select distinct yourcol from t5
) t
group by id
having count(*) >= 2然后,您可以将>= 2更改为您想要的任何数字。
顺便说一句--如果有问题的列不包含重复项,则可以从子查询中删除distinct。
https://stackoverflow.com/questions/17712998
复制相似问题