查找特定值的组合 [英] Finding combinations of specific values

查看:62
本文介绍了查找特定值的组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何在下面编写查询。

I don't know how to write the query for below.

我的桌子是

col1 col2 
5   1
5   5
5   6
5   7
4   5
4   8
4   9
4   3
3   3
3   5

I需要选择不同的col1 id,其中col2中两个参数都存在。
例如如果我发送6,7,它应该发送给我5

I need to select distinct col1 id where both parameters exists in col2. eg. if i send 6,7 it should send me 5

推荐答案

尝试:

SELECT col1
FROM mytable
WHERE col2 IN (6, 7)
GROUP BY col1
HAVING COUNT(DISTINCT col2) = 2

这篇关于查找特定值的组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆