SpectraMedix Interview Question

SQL Group by related query