私は患者のデータベースを持っています。患者 ID を識別子として使用し、投薬とアクションの複数の Start_Date と Stop_Date を使用します。
私の問題はそれを照会する方法です
WHERE action = 1 and start_date BETWEEN '01/10/2012' and '01/10/2013'
and where action = 1 is their FIRST Start_date
治療表:
Patient_ID
Start_Date Varchar
Stope_Date Varchar
Action Varchar
コード: 1 = 開始; 2 = 停止。3 = 変更
お気に入り:
Patient_ID | Medication_Code |Action| Start_Date | Stop_Date
10001 | Med008 | 2 | 01/01/2010 | 10/08/2012
| Med012 | 1 | 02/09/2013 |
| Med088 | 1 | 22/07/2009 |
10002 | Med003 | 2 | 01/01/2009 | 01/03/2011
| Med012 | 1 | 02/03/2012 |
| Med081 | 1 | 22/07/2013
10011 | Med018 | 2 | 11/02/2010 | 10/08/2012
| Med011 | 1 | 12/09/2013 |
| Med028 | 1 | 25/03/2013
患者には複数の start_date があることがわかります。次のようなものを使用する場合
where start_date between 01/01/2012 and 01/01/2013 and action = 1
action =1 and between 01/01/2012 and 01/01/2013
彼らが持っている最初のStart_dateでなくても、すべてを教えてくれます。
したがって、この例では IF ITS A WORKING スクリプト
Select patient_ID, Start_Date, Action, Medication_code
from Patient
Where start_date EARLIEST 01/01/2012 and 01/01/2013 and action = 1
必要な出力:
10002 22/07/2013 1 Med081
10011 25/03/2013 1 Med028
よろしくお願いします... 質問をお待ちしています。