Fun solving a SQL problem (that I will never use in production)