Find visits that have a follow-up date, and count how many subsequent visits (by the same patient with the same doctor) occurred on or after the follow_up_date. Return visit_id, patient_id, doctor_id, visit_date, follow_up_date, and subsequent_visit_count. Only include visits where follow_up_date is not NULL. Order by subsequent_visit_count descending.
Schema
🔑idINT
🔗patient_idINT
🔗doctor_idINT
visit_dateTEXT
diagnosisTEXT
notesTEXTNULL
follow_up_dateTEXTNULL
statusTEXT
postgresql
Run your query to see results
Press Ctrl + Enter to execute