我正在用ID的前3次访问高度值更新表格,例如...
ID fvdate访问Ht_date Ht_value
1 06jun2010 1 06jun2010 168
1 06jun2010 2 18Dec2010 168.2
1 06jun2010 3 ? ?
2 12dec2011 1 25dec2011 175
2 12dec2011 2 12feb2012 175.8
2 12dec2011 3 ? ?
对于前2次访问,我进行了很好的更新。 但是在更新第3次访问时,我遇到了一些麻烦...
我使用以下代码用日期更新值
update mytab
set ht_DT = b.Record_date,
ht = b.Height
FROM mytaba JOIN anthropometry b
ON a.mno = b.patient_id and Visit ='1' and
b.record_date = fvdate
update mytabset
ht_DT = b.Record_date,
ht = b.Height
FROM mytaba JOIN anthropometry b
ON a.mno = b.patient_id and Visit ='2' and
b.record_date = (select min(record_date) from anthropometry cc where
a.mno = cc.patient_id and cc.record_date > fvdate)
update mytabset ht_DT = b.Record_date, ht = b.Height FROM
mytaba JOIN anthropometry b ON a.mno =
b.patient_id and Visit ='3' and b.record_date =
(select min(record_date) from anthropometry cc where
a.mno = cc.patient_id and cc.record_date > a.ht_Dt and Visit ='2')
请更正我在给定代码上的错误。