Good morning,
while building a query from a table (t1) I need a sorted, formatted grouping
(dt = datetime, formatted in minutes).
Simple query:
Code:
SELECT DATE_FORMAT(t1.dt,"%Y-%m-%d %H:%i") AS 'thetime', COUNT(*) AS "howmany"
FROM t1
GROUP BY thetime
ORDER BY thetime ASC;
So far so good.
Result of that query (example):
Code:
2009-03-06 00:30, 5
2009-03-06 00:31, 4
2009-03-06 00:33, 8
...but I prefer...
Code:
2009-03-06 00:30, 5
2009-03-06 00:31, 4
2009-03-06 00:32, 0 <- !
2009-03-06 00:33, 8
2009-03-06 00:34, 0 <- !
Why? The data will be processed into an image with a timeline. If the time isn't progressing continuously, the image gets incoherent if I have timespans (minutes) without any records.
How can I account those ticks without entries in the table t1?
RDBMS: MySQL (5.x).
Two possible solutions from myself:
1. using a 2nd table with "all" ticks and bound via JOIN to t1,
2. processing the resultset with another programm to add the left-out ticks.
Both would be a bit cumbersomely and I guess there are easier solutions which I just haven't found yet.
Thanks in advance for any hint into the right direction!
Björn