I have two tables
Table Users
:
user_id Name
1 John
2 Alice
3 Tom
4 Charles
Table Events
:
id event_id start_date end_date user_id
1 1 2013-03-02 2013-03-03 1
2 2 2013-03-02 2013-03-03 3
3 3 2013-03-04 2013-03-04 1
4 2 2013-03-10 2013-03-15 2
I already made the "input" part and is not possible to have two events for the same user in the same day (no overlapping).
I provide the month and the year as variables.
I would like to have a mysql query with results like this:
user_id 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 0 1 1 3 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2
3 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0
Thank you!
I tryed this:
UPDATED
Output:
Here is SQLFiddle demo