Mysql需要每周COUNT题词持续12周

时间:2013-03-07 14:16:57

标签: mysql date count week-number

本周我已经算上了铭文。 但我需要在过去12周内每周计算一次铭文,并将其发送到阵列中。

我的实际要求是:

SELECT COUNT(*) FROM PERSON
YEAR(date_inscription) = YEAR(NOW())
AND WEEK(date_inscription) = WEEK(NOW())

1 个答案:

答案 0 :(得分:5)

SELECT YEARWEEK(date_inscription) as yweek,
       COUNT(*) as cnt
FROM PERSON
where YEARWEEK(date_inscription) >= YEARWEEK(curdate()) - 12
group by yweek