Solving these problems in SQL requires a number sequence