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周。出了什么问题?
答案 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