2012-09-17 49 views
-1

我試圖從我們的電子患者記錄系統中存儲在的'comments'列中的來自sql的數千患者記錄中獲取信息。使用SQL從電子患者記錄中提取研究信息

由於要求的靈敏度,並與患者身份信息的問題,我只希望這個「comments」列拉必要的數據,而不將其將違反病人數據的附加和未必要的信息。

在該「comments」列(這是一個免費的文本列)包含其中寫入了關於每個病人,當他們看到自己的顧問文本的負載,如diagnosismedicationgeneral notes

對於我的研究,我只需要提取的患者,其中這個「意見」一欄包括的話:

米氮平,Shcizophrenia和雙極

這三個詞必須存在在每一個評論欄中,每個病人被認爲是有效的研究目的。因此,如果其中一個患者評論包含三個關鍵詞中的兩個,我將不會使用它(我不希望看到它,因爲它被認爲是不必要的提取) - 我只想看到任何'comments'都有這3個關鍵詞。

任何人都可以幫忙嗎?

+0

你嘗試過什麼?發佈一些工作查詢,無所謂返回錯誤的結果,是一個開始,也許你離實際解決方案不遠。你使用的是什麼樣的RDBMS,MS SQL Server,MySQL,Oracle,Postgre?請重新提出您的問題。所有這些行動將幫助您獲得更好的答案。 – Yaroslav

+1

當然,如果你精確地拼寫精神分裂症,你將會得到更好的結果。 – HLGEM

回答

1

你可以使用這樣的事情:

select * 
from yourtable t1 
where exists (select * 
       from yourtable t2 
       where comments like '%Mirtazapine%' 
       and t1.id = t2.id) 
    and exists (select * 
       from yourtable t2 
       where comments like '%Shcizophrenia%' 
       and t1.id = t2.id) 
    and exists (select * 
       from yourtable t2 
       where comments like '%bi-polar%' 
       and t1.id = t2.id) 

或者:

select * 
from yourtable t1 
where comments like '%Mirtazapine%' 
    and exists (select * 
       from yourtable t2 
       where comments like '%Shcizophrenia%' 
       and t1.id = t2.id) 
    and exists (select * 
       from yourtable t2 
       where comments like '%bi-polar%' 
       and t1.id = t2.id) 

看到SQL Fiddle with Demo