[英]Sqlplus exclude results that have a string
有沒有一種方法可以查詢表以排除具有特定字符串的具有唯一ID的行?
示例:我有一個記錄用戶活動的表:ID操作
ID activity
jjl Logged in
jjl updated user contie
jjl updated user kalka
jjl Logged off
cdl Logged in
cdl updated user pilda
cdl updated user dkcll
cdl updated user ccffrr
我試圖排除任何帶有“已注銷”消息的ID,這意味着jjl根本不會出現在我的查詢結果中。
假設ID永遠不能為空,我將使用:
select *
from table
where id not in (
select id
from table
where activity = 'Logged off'
)
如果可以為null,我將使用:
select *
from table t1
where not exists (
select null
from table t2
where t2.id = t1.id
and activity = 'Logged off'
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.