2013-02-12 22 views
0

首先,讓我從我使用的表開始。他們看起來像這樣:選擇任何數據表中不存在字符串的ID

Table - Transaction 
=================== 
trans_id 
name 

Table - Checkpoint 
================== 
trans_id 
checkpoint_id 
checkpoint_data 

事務可以有多個檢查點,並且檢查點只能有一個事務。

我無法形成一條SQL語句,它將選擇某個名稱的所有事務的trans_id,該名稱在任何相關檢查點中不包含checkpoint_data中的某些字符串。

此SQL語句的外觀如何?我使用的是Oracle,但是任何SQL應指向我朝着正確的方向

回答

1
select trans_id 
from transactions t 
left outer join checkpoint c on c.trans_id = t.trans_id 
where t.name = 'transaction name' 
group by t.trans_id 
having sum(case when contains(checkpoint_data, 'some string') > 0 
       then 1 
       else 0 
      end) = 0 
+0

+1。 。 。你可以添加問題中提到的'where name = SOMENAME'條件。 – 2013-02-12 18:51:11

+0

@GordonLinoff:謝謝。完全忘了那個。 – 2013-02-12 18:52:21

0
Select distinct(ch.trans_id) from checkpoint ch join transaction t on ch.trans_id=t.trans_id and t.name like '%test%' and ch.chech_point not like '%exclude%' 
相關問題