Script to select all the new patients for the last 4 years. Note that only past patients are included (AptDateTime < curdate())
SELECT
YEAR (apt.AptDateTime) as year,
MONTH(apt.AptDateTime) as month,
count(*) as count
FROM
appointment apt,
patient pts
WHERE
apt.PatNum = pts.patNum and
apt.IsNewPatient = 1 AND
HOUR(apt.AptDateTime) BETWEEN 8 AND 18 and
YEAR(apt.AptDateTime) >= YEAR(DATE_SUB(CURDATE(), INTERVAL 4 YEAR)) AND
apt.AptDateTime < curdate()
GROUP BY
month, year
ORDER by
month, year;