I would like to generate a list of clients who turned 18 while in treatment with us?
This is actually a pretty simple query. You would just have to identify everyone who was younger than 18 on their intake date, and older than 17 before being discharged.
SELECT
lastname AS "Last Name",
firstname AS "First Name",
id,
intakedate,
dischargedate
FROM
sos.patients
WHERE
sos.AGEINYEARS(dob,intakedate) < 18 AND sos.AGEINYEARS(dob,COALESCE(dischargedate,today())) > 17
ORDER BY
lastname,firstname, id