Write a complex SQL query utilizing window functions to track patient visits over a rolling 30-day window.
Use the provided patient, provider, and visit data. Include completed visits only, and count completed visits for the same patient from the current visit date through the preceding 29 calendar days.
Output
- One row per completed visit, including
visit_id, patient_id, patient_name, visit_date, provider_name, and rolling_30_day_visits
- Use
Unknown when a visit has no matching provider
- Order by
patient_id, visit_date, then visit_id