1.我认为那是行不通的。您可以在不进行舒张测量的情况下进行收缩测量(例如,通过触诊而不是使用血压计测量血压),同一个表格记录了许多不同类型的结果。这个问题可能会使用一个标题,更多地是关于SQL,更少地是关于SQL的医学应用。@Graham Chiu标题和标
1.我认为那是行不通的。您可以在不进行舒张测量的情况下进行收缩测量(例如,通过触诊而不是使用血压计测量血压),同一个表格记录了许多不同类型的结果。这个问题可能会使用一个标题,更多地是关于SQL,更少地是关于SQL的医学应用。@Graham Chiu标题和标,sql,Sql,1.我认为那是行不通的。您可以在不进行舒张测量的情况下进行收缩测量(例如,通过触诊而不是使用血压计测量血压),同一个表格记录了许多不同类型的结果。这个问题可能会使用一个标题,更多地是关于SQL,更少地是关于SQL的医学应用。@Graham Chiu标题和标记都是用来表示问题的编程相关内容的。如果有人在看问题列表,标题比标签更明显,应该清楚地表达问题。这里的人不倾向于考虑与SQL相关的血压管理。这假设每位患者每天只有一次血压测量。不,它只假设最后一次就诊是max(rdate)。如果根据提供的信息,
1.我认为那是行不通的。您可以在不进行舒张测量的情况下进行收缩测量(例如,通过触诊而不是使用血压计测量血压),同一个表格记录了许多不同类型的结果。这个问题可能会使用一个标题,更多地是关于SQL,更少地是关于SQL的医学应用。@Graham Chiu标题和标记都是用来表示问题的编程相关内容的。如果有人在看问题列表,标题比标签更明显,应该清楚地表达问题。这里的人不倾向于考虑与SQL相关的血压管理。这假设每位患者每天只有一次血压测量。不,它只假设最后一次就诊是
max(rdate)
。如果根据提供的信息,每次访问都有多个读数,我们无法决定选择哪一个,他会得到多个读数。它将显示任何适用的选项,因此如果在同一次就诊中有3个收缩和3个舒张,那么所有6行都将返回。@JNK,我想您已经找到了。我想有两个r1
引用应该是R
。我在Firebird'SQL error code=-206 Column unknown R2.RVALUE'中得到了一个SQL语法错误。我怀疑这个查询还返回了患者上一次血压良好的日期。我尝试了这个查询,但我认为它给出了他们上一次血压正常的日期,但我想知道他们上次来的时候他们的血压是否正常。所以,如果他们一年前有一个很好的阅读,昨天来了,他们的血压不正常,它返回了一年前的日期
patient integer
rdate date
rvalue integer
rtype vchar
select patient, max(rdate) as maxdate
from results
where rtype = 'systolic' and rvalue > 0
group by patient
select r.patient, max(r.rdate) as maxdate
FROM results as R
INNER JOIN results as R2 ON r2.Patient=r.patient AND r.rdate=r2.rdate
WHERE r.type='systolic' and r.rvalue BETWEEN 0 and 140
AND r2.type='diastolic' and r2.rvalue BETWEEN 0 and 90
GROUP BY r.patient
SELECT patient, MAX(rdate) AS max_rdate
FROM (
SELECT patient, rdate, MIN(CASE WHEN RTYPE = 'systolic' THEN rvalue END) AS min_systolic,
MIN(CASE WHEN RTYPE = 'diastolic' THEN rvalue END) AS min_diastolic
FROM BPResults
GROUP BY patient, rdate
) AS results
WHERE min_systolic < 140
AND min_diastolic < 90
GROUP BY patient
select patient, max(rdate) as ldate from digital
where rtype = 'Diastolic' and RDATE between (?) and (?)
group by patient
intersect
select patient, rdate as ldate from digital
where rtype = 'Diastolic' and RDATE between (?) and (?)
and rvalue < 90
intersect
select patient, rdate as ldate as digital where rtype = 'Systolic' and
select dia.patient as patient
, dia.rdate as bp_date
, min(dia.rvalue) as dia_bp -- best dia bp for that date
, min(sys.rvalue) as sys_bp -- best sys bp for that date
from results dia
, results sys
where dia.patient = sys.patient
and dia.rdate = sys.rdate -- both bp on same date
and dia.rtype = 'diastolic'
and sys.rtype = 'systolic'
group by dia.patient
, dia.rdate
having min(dia.rvalue) < 90 -- under 90 bp
and min(sys.rvalue) < 140 -- under 140 bp
and dia.rdate = -- and that date is
( select max(lst.rdate) -- the last date
from results lst
where lst.patient = dia.patient -- for that patient
and lst.rtype in ( 'diastolic' -- with a bp row
, 'systolic' ) )
select bp.patient
, bp.rdate -- the latest bp date
, bp.rtype
, min(bp.rvalue) -- best bp for that date
from results bp
where bp.rtype in ('diastolic', 'systolic')
and bp.rdate = -- and the bp date is
( select max(lst.rdate) -- the last bp date
from results lst
where lst.patient = bp.patient -- for that patient
and lst.rtype in ( 'diastolic' -- in which there is a bp row
, 'systolic' ) )
group by bp.patient
, bp.rdate
, bp.rtype
having ( min(bp.rvalue) < 90 -- under 90 bp
and bp.rtype = 'diastolic') -- when diastolic
or ( min(bp.rvalue) < 140 -- or under 140 bp
and bp.rtype = 'systolic' ) -- when systolic