COUNT with GROUP BY gives one row per group:
SELECT encounter_type, COUNT(*) AS encounters
FROM hd_encounters
GROUP BY encounter_type;
Before counting, decide what one row is:
COUNT(*) counts rows. In hd_encounters that is visits and stays, not people.
COUNT(DISTINCT patient_id) counts people.
COUNT(column) skips rows where that column is empty, which quietly drops patients still in a bed when the column is discharge_date.
HAVING filters groups after counting, the way WHERE filters rows before.
One row per patient, so COUNT(*) counts people here.