This advanced SQL exercise is part of the book: Advanced SQL – Practical Techniques and Use-Cases, which includes 100 day-to-day SQL challenges (and solutions), need-to-know advanced features, and key concepts.
An interesting SQL exercise. Given the following table of dates:
CREATE TABLE dates (date_id date, period int) GO
This table represents all days in the year 2016; each day is assigned to a specific period. These periods were defined arbitrarily, based on the following rules:
- A period whose number is 1 was defined for the months: 1, 3, 5, 7, 9
- A period whose number is 2 was defined for the months: 2, 4, 6, 8
- A period whose number is 3 was defined for the months: 10, 11, 12