Assumindo seu
postid
s são contíguos em sua tabela, então esta consulta:SELECT
DATE_FORMAT(b.date, '%Y-%m-%d') date,
COUNT(c.postid)
FROM
(
SELECT
(SELECT MAX(date) FROM ex) + INTERVAL 3 DAY - INTERVAL a.postid DAY AS date
FROM
ex a
) b
LEFT JOIN
ex c ON c.date = b.date
GROUP BY
b.date
ORDER BY
b.date
produz:
date COUNT(c.postid)
2012-01-01 2
2012-01-02 2
2012-01-03 0
2012-01-04 2
2012-01-05 1
2012-01-06 0
2012-01-07 0
Consulte http://sqlfiddle.com/#!2/2cf8d/2
Se o seu
postid
s não são contíguos, então você pode usar um ids
tabela de ids contíguos:SELECT
DATE_FORMAT(b.date, '%Y-%m-%d') date,
COUNT(c.postid)
FROM
(
SELECT
(SELECT MAX(date) FROM ex) + INTERVAL 3 DAY - INTERVAL a.id DAY AS date
FROM
ids a
) b
LEFT JOIN
ex c ON c.date = b.date
GROUP BY
b.date
ORDER BY
b.date DESC
LIMIT 7
Consulte http://sqlfiddle.com/#!2/13035/1