如何获取与所有值集匹配的记录。 [英] How to get records which matches all set of values.?

查看:70
本文介绍了如何获取与所有值集匹配的记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在过去的两天里一直在努力。我的问题是我想编写MySql查询,以便获取所有匹配所有值集的记录。



假设:我想获取属于10,20的所有emps, 30 deptno.Let假设deptno 30不存在于表中,因此不要获取10,20的记录。只返回空。



我尝试过的事情:



I am struggling from last 2 days. My Question is i want write MySql query so it fetch all records that matches all set of values.

Suppose: I want to fetch all emps belongs to 10,20,30 deptno.Let suppose deptno 30 is not present in table so dont fetch records for 10,20. just return empty.

What I have tried:

I tried: Mysql Query using IN Operator

  mysql > select * from emp where deptno in (10,20,30);
  o/p = this query retrieving emps belong to 10,20 deptno. 

推荐答案

if ((select count(*) from emp where deptno  = 10) > 0 and (select count(*) from emp where deptno  = 20) > 0 and (select count(*) from emp where deptno  = 30) > 0)
begin
select * from emp where deptno in (1,2,3)
end







this is brute force but i will try to find a better solution


这篇关于如何获取与所有值集匹配的记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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