A sample image of this SQL report run in the Database Viewer is shown below:
This will show you all active patients whose BMI is greater than 95%.
- The SQL only pulls patients whose status is ACTIVE.
- It only pulls patients ages 2 and up, since younger children don't have a BMI defined.
- It pulls patients whose BMI is GREATER than 95, not GREATER THAN OR EQUAL to 95.
- It looks at the patient’s most recent BMI. So, if a child's BMI is currently under 95 even though the patient's previous three BMIs were over 95, the patient won't appear in the grid.
To highlight and copy the code below to your clipboard, simply click the Copy button.
select p.* , pc.bmi_percent from ( (select patno, max(date1) as most_recent from physical_chart group by patno) p left outer join physical_chart pc on pc.patno = p.patno and pc.date1 = p.most_recent ) inner join register on register.patno = p.patno where status_pat = 'ACTIVE' and bmi_percent > 95