首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >SQL过滤查询

SQL过滤查询
EN

Stack Overflow用户
提问于 2019-04-16 01:09:37
回答 4查看 37关注 0票数 -1

我试着解决这个问题,但需要一些帮助。

编辑了这篇文章,我想我需要解决这个问题。我需要从T2中筛选出行,其中属于特定AcctId的BoxNums的所有行的状态都设置为55,该AcctId=Y的状态设置为自动

EN

回答 4

Stack Overflow用户

发布于 2019-04-16 01:10:52

您可以进行聚合:

代码语言:javascript
复制
select accountid
from table t
group by accountid
having min(status) = max(status) and min(status) = 55;

对于所有列,您可以执行JOIN或使用NOT EXISTS

代码语言:javascript
复制
select t2.*
from t1 inner join
     t2
     on t2.accountid = t1.accountid
where t1.auto = 'Y' and
      t2.status = 55 and
      not exists (select 1 from table t11 where t2.accountid = t11.accountid and t11.status <> t2.status);
票数 0
EN

Stack Overflow用户

发布于 2019-04-16 01:57:24

如果要查看原始数据,请使用not exists

代码语言:javascript
复制
select t.*
from t1 join
     t2
     on t1.accountid = t2.accountid
where t1.auto = 'Y' and
      not exists (select 1
                  from t t2
                  where t2.accountid = t.accountid and t2.status <> 55
                 );
票数 0
EN

Stack Overflow用户

发布于 2019-04-16 02:36:40

这是你想要的吗?

这是一种简单的subquery用法,给出了特定帐户in的T2数据,该帐户in存在于T2中,在T1中也有一个值Y

代码语言:javascript
复制
      SELECT  Account_Id, 
      Box_num,Status FROM T2 WHERE 
       STATUS 
      =55 and account_id in (SELECT 
        account_id from T1 where auto='Y')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55694192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档