我如何才能获得MySQL的最后10周?

时间:2012-11-21 21:50:14

标签: mysql count

SELECT WEEK( `date_posted` ) AS week, COUNT( 1 ) AS aantal
FROM `news`
GROUP BY week
ORDER BY week DESC
LIMIT 0 , 10

这不起作用。输出是:

    week  aantal
    52  41
    51  56
    50  49
    49  56
    48  62

但是,我们还没有在第52周。出了什么问题?

1 个答案:

答案 0 :(得分:1)

我认为你需要一个WHERE条款:

SELECT WEEK( `date_posted` ) AS week, COUNT( 1 ) AS aantal
FROM `news` 
WHERE `date_posted` >= (curdate() - interval 10 week)
GROUP BY week
ORDER BY week DESC
LIMIT 0 , 10