[英]SQL query extraction: same row with same id
I am bit stuck on the following. 我对以下内容有些困惑。 The data of the table as follows: 该表的数据如下:
sid eid description returncode responsemessage State
1 T-1 200 OK Sent
1 T-1 Helloworld Processed
I cannot use stored procedure, the application only supports a SQL query. 我无法使用存储过程,该应用程序仅支持SQL查询。
select *
from table
where eid='T-1'
and returncode='200'
and returnmessage='OK'
and state='Sent'
May be something needs to be added here?? 可能需要在此处添加一些内容??
Any tips or ideas on how I can achieve this with SQL query? 关于如何使用SQL查询实现此目标的任何提示或想法?
Update: Oracle Database, I want to retrieve "HelloWorld" from the description column but it should be only retrieved when State=Sent has returncode=200 and responsemessage=ok 更新:Oracle数据库,我想从描述列中检索“ HelloWorld”,但仅在State = Sent具有returncode = 200并且responsemessage = ok时才应检索
I'm not entirely clear on what you are trying to accomplish, but maybe you meant something like this: 对于您要完成的工作,我还不太清楚,但是也许您的意思是这样的:
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
I think you can do this using exists
: 我认为你可以使用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'
);
You might want to include equality on sid
as well, but that is not clear from the question. 您可能还希望在sid
上包含相等性,但是这个问题尚不清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.