CVS Health Interview Question

SQL query for group summarizing