Mfcer__, Я тут посидел чуток с твоим запросом, думаю он у тебя вообше не должен работать.
Вот моя версия запроса:
select
pub_date as Date,
case when good.count is NULL then 0 else good.count end as good,
case when bad.count is NULL then 0 else bad.count end as bad
from
posts left join
(SELECT
posts.pub_date AS date,
count(1) as count
FROM posts,deals
WHERE
deals.post_id = posts.id and
deals.is_good = false
group By posts.pub_date) as bad
on pub_date=bad.date left join
(SELECT
posts.pub_date AS date,
count(1) as count
FROM posts,deals
WHERE
deals.post_id = posts.id and
deals.is_good = true
group By posts.pub_date) as good
on pub_date=good.date
where
pub_date BETWEEN '2007-01-01' AND '2008-01-01'
group by pub_date
order by pub_date asc
запрос состоит из 3 селектов. На pub_date не мешало бы поставить индекс для ускорения работы. А вообше по идее говоря, лучше было бы сделать два запроса:
SELECT
posts.pub_date AS date,
count(1) as count
FROM posts,deals
WHERE
deals.post_id = posts.id and
deals.is_good = true AND
posts.pub_date BETWEEN '2007-01-01' AND '2008-01-01'
group By posts.pub_date
Один с true и второй с false и затем их аппликативно склеивать.