[英]SQL query extraction: same row with same id
我对以下内容有些困惑。 该表的数据如下:
sid eid description returncode responsemessage State
1 T-1 200 OK Sent
1 T-1 Helloworld Processed
我无法使用存储过程,该应用程序仅支持SQL查询。
select *
from table
where eid='T-1'
and returncode='200'
and returnmessage='OK'
and state='Sent'
可能需要在此处添加一些内容??
关于如何使用SQL查询实现此目标的任何提示或想法?
更新:Oracle数据库,我想从描述列中检索“ HelloWorld”,但仅在State = Sent具有returncode = 200并且responsemessage = ok时才应检索
对于您要完成的工作,我还不太清楚,但是也许您的意思是这样的:
select T1.*
from table T1
INNER JOIN table T2
ON T2.SID = T1.sid
where T1.eid='T-1'
and T1.returncode='200'
and T1.returnmessage='OK'
and T1.state='SENT'
AND T2.description IS NOT NULL
我认为你可以使用exists
做到这一点:
select t.*
from t
where t.description is not null and t.eid = 'T-1' and
exists (select 1
from t t2
where t2.eid = t.eid and t2.returncode = '200' and
t2.returnmessage = 'OK' and t2.state = 'SENT'
);
您可能还希望在sid
上包含相等性,但是这个问题尚不清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.