Is it possible to construct a query to create multiple columns based on multiple conditions and aggregate by time. For example a simple table like so:
id value created
1 45 datetime
2 52 datetime
3 24 datetime
4 33 datetime
5 20 datetime
I can get all values between 10 and 20 per week of the year like so:
SELECT count(*) as '10-20', week(created) as 'week', year(created) as 'year'
FROM table
WHERE value > 10 AND value < 20
GROUP BY year(created), week(created)
This will give me for example:
10-20 week year
40 1 2014
21 2 2014
3 33 2014
I could repeat the query for ranges 20-30
,30-40
, 40-50
and manual join the outputs but I'd like a single queries combining these into a table, so the output would be:
10-20 20-30 30-40 40-50 week year
40 0 33 42 1 2014
21 1 0 2 1 2014
0 0 32 0 12 2014
3 42 34 32 33 2014