我有以下“统计数据”表:
我希望mysql查询以点击总和返回最新的5个日期。所以开始记录应该是2015-01-12
输出:
到目前为止,我已根据我的输出编写了以下查询。
SELECT logdate, (
SELECT SUM(clicks)
FROM stats t2
WHERE t2.logdate = t1.logdate
ORDER BY t2.logdate
DESC LIMIT 0,5
) as clicks
FROM stats t1
GROUP BY t1.logdate
ORDER BY t1.logdate ASC
LIMIT 0, 5