Supponendo che il tuo postid
s sono contigui nella tabella, quindi questa query:
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
produce:
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
Vedi http://sqlfiddle.com/#!2/2cf8d/2
Se il tuo postid
s non sono contigui, quindi puoi usare un ids
tabella di ID contigui:
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
Vedi http://sqlfiddle.com/#!2/13035/1