I have a table EventLogs which records a given Event's details such as the date of the event and the fee.
+------+----------+---------------------------+-------------------+
| id | place_id | start_at | total_fee_pennies |
+------+----------+---------------------------+-------------------+
| 4242 | 40 | 2013-10-20 19:00:00 +0100 | 8700 |
| 4288 | 48 | 2013-10-22 20:00:00 +0100 | 8000 |
| 4228 | 141 | 2013-10-17 19:30:00 +0100 | 20000 |
| 4232 | 19 | 2013-10-20 19:30:00 +0100 | 8000 |
| 4239 | 5 | 2013-10-20 19:30:00 +0100 | 6800 |
| 4269 | 6 | 2013-10-20 20:00:00 +0100 | 7000 |
| 4234 | 98 | 2013-10-20 20:00:00 +0100 | 6900 |
I would like to be able to aggregate this data total fee by week, I believe this is a PIVOT?
So I'd select them for a given month:
"SELECT \"event_logs\".* FROM \"event_logs\" WHERE (event_logs.start_at BETWEEN '2013-10-01' AND '2013-10-31')"
And then somehow aggregate them by distinct place_id and by week using start_at (5 weeks in a month, usually?) with the total fee for each week.
place_id, week 1, week2, ...
But I'm not sure how to do this?