Categorize patients into risk levels based on multiple criteria. A patient is 'High Risk' if they have more than 3 visits with abnormal lab results, 'Medium Risk' if 1-3, and 'Low Risk' if none. Return patient full name, abnormal_visit_count, and risk_level. Include all patients who have had visits. Order by abnormal_visit_count descending.
Schema
🔑idINT
first_nameTEXT
last_nameTEXT
date_of_birthTEXT
genderTEXT
emailTEXT
phoneTEXTNULL
blood_typeTEXT
cityTEXT
stateTEXT
🔗insurance_idINTNULL
created_atTIMESTAMP
postgresql
Run your query to see results
Press Ctrl + Enter to execute