我有一個表PatientLab我有一組測試如下選擇第一個和最後一個測試組Labtests
patientid labtest dateordered result
100 cd4 1/1/14 500
100 cd4 1/4/14 200
100 cd4 1/5/15 800
100 vl 1/4/14 564
200 cd4 1/5/16 455
200 cd4 1/6/16 678
200 cd4 1/7/16 234
200 cd4 1/8/16 356
200 vl 1/7/16 1000
我想要的結果的;
patientid FirstCD4 FirstCD4Date LastCD4 LastCD4Date
100 500 1/1/14 800 1/5/15
200 455 1/5/16 356 1/8/16
正在使用PostgreSQL 9
你嘗試過什麼呢? – etsa
我試圖'選擇patientid,dateordered,導致從PatientLab 其中(patientid)IN( 選擇patientid,最大值(dateordered)從PatientLab AS dateordered 其中LABTEST = 'CD4' 組由patientid )'是能夠只能得到最大值,但無法同時從最大值和最小值中獲得最大值和最小值 –
對於患者只有一個CD4的情況,我們是否還應該包括一行以及我們所擁有的細節?對於那些沒有CD4的人也一樣嗎? – toonice