Optimal query to fetch same-rows multiple times
The legend says:
We have a table of Events with 3 fields: id (INT), date_start (DATE), date_end (DATE), and in this table we have numerous of rows which can have same ranges in date_start-date_end or different.
For example: we can have an event that lasts from 2011-06-01 to 2011-06-08 and of course we can have an event that lasts from 2011-06-01 to 2011-06-01.
The question is:
What are the most optimal que开发者_StackOverflowries to:
- Fetch events for a month day by day to get such thing:
- 2011-06-01
- ID: 1
- ID: 2
- ID: 3
- ID: 4
- ID: 5
- ...
- 2011-06-02
- ID: 1
- ID: 3
- ID: 4
- ...
- 2011-06-02
- ID: 3
- ID: 6
- ...
- and so on.
- Fetch all possible months and number of events for those months to get such thing:
- 2011-06, 00
- 2011-07, 05
- 2011-08, 25
- 2011-09, 15
- 2011-10, 23
- 2011-11, 00
- 2011-12, 11
- 2012-01, 00
- and so on.
精彩评论