RMG Networks interview question

SQL query write to get tex