slice interview question

Basic SQL queries and Some logic