我试着解决这个问题,但需要一些帮助。
编辑了这篇文章,我想我需要解决这个问题。我需要从T2中筛选出行,其中属于特定AcctId的BoxNums的所有行的状态都设置为55,该AcctId=Y的状态设置为自动
发布于 2019-04-16 01:10:52
您可以进行聚合:
select accountid
from table t
group by accountid
having min(status) = max(status) and min(status) = 55;
对于所有列,您可以执行JOIN
或使用NOT EXISTS
:
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);
发布于 2019-04-16 01:57:24
如果要查看原始数据,请使用not exists
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
);
发布于 2019-04-16 02:36:40
这是你想要的吗?
这是一种简单的subquery
用法,给出了特定帐户in的T2
数据,该帐户in存在于T2
中,在T1中也有一个值Y
。
SELECT Account_Id,
Box_num,Status FROM T2 WHERE
STATUS
=55 and account_id in (SELECT
account_id from T1 where auto='Y')
https://stackoverflow.com/questions/55694192
复制相似问题