[英]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.