I have a simple table of timestamps , types and counts like
timestamp |t|c
==============
1415024797|1|1
1415025774|1|1
1415202785|1|1
1415204559|1|1
1415204593|1|2
1415629057|1|1
1415791322|2|1
1415797887|1|1
now i get a result which counts the c column group by t and for a certain date YYYY-MM-DD
I have to add 3600 to the timestamp to respect timezone offset!
SELECT From_unixtime(a.timestamp + 3600, '%Y-%m-%d') AS date,
Count(From_unixtime(a.timestamp + 3600, '%Y-%m-%d')) AS count,
a.t AS type
FROM table AS a
WHERE a.timestamp >= 1415322000 AND a.timestamp < 1415926800
GROUP BY From_unixtime(a.timestamp + 3600, '%Y-%m-%d'),
a.t
ORDER BY a.timestamp DESC
with this query I get something like
date |count | type
==========================
2014-12-03 | 3 | 1
2014-12-03 | 1 | 2
2014-12-04 | 3 | 1
2014-12-05 | 3 | 3
2014-12-07 | 4 | 2
2014-12-07 | 7 | 3
....
But I would like to get
date | t_1 | t_2 | t_3
=============================
2014-12-03 | 3 | 1 | 0
2014-12-04 | 3 | 0 | 0
2014-12-05 | 0 | 0 | 3
2014-12-06 | 0 | 0 | 0
2014-12-07 | 0 | 4 | 7
....
So on each line a date with all counts of a certain type.
- There are only 3 types possible (1 =>
t_1, 2 =>t_2, 3 =>t_3) - Also dates with 0 values (
2014-12-06) should be included - to build the query I'll use PHP (foreach)