【发布时间】:2009-06-03 14:00:47
【问题描述】:
我正在尝试对我们的数据库运行报告。我们想知道每个行业每月的新注册量。我写了这个查询:
SELECT
COUNT(j.jobseeker_id) as new_registrations,
i.description as industry_name,
MONTHNAME(j.created_at)
FROM
tb_jobseeker as j, tb_industry as i
WHERE
YEAR(j.created_at) = 2009
AND
i.industry_id = j.industry_id
GROUP BY
i.description, MONTHNAME(j.created_at)
HAVING
MONTHNAME(j.created_at) = MONTHNAME(NOW());
当我运行这个查询时,我得到一个空的结果集。但是,如果我运行以下命令:
SELECT
COUNT(j.seeker_id) as new_registrations,
i.description as industry_name,
MONTHNAME(j.created_at)
FROM
tb_seeker as j, tb_industry as i
WHERE
YEAR(j.created_at) = 2009
AND
i.industry_id = j.industry_id
GROUP BY
i.description, MONTHNAME(j.created_at)
HAVING
MONTHNAME(j.created_at) = 'June';
它返回我正在寻找的结果。
有什么帮助吗?我被难住了。
更新:查询将在过去一个月的每个月底或下一个月初运行。所以,我们现在是在六月,但它需要运行到五月。希望这是有道理的。
【问题讨论】: