我有一个包含table
和date
列的表total
。
如何将过去20周内每周sum
列的total
汇总到sysdate
?
答案 0 :(得分:2)
SELECT *, CONCAT(YEAR(`sysdate`), '/', WEEK(`sysdate`)) AS `year_week`
FROM `table`
GROUP BY `year_week`
ORDER BY `year_week` DESC
LIMIT 20;
答案 1 :(得分:2)
select trunc(date,'D'), sum(total)
from table
where date >= trunc(sysdate - 20*7, 'D')
group by trunc(date,'D')
order by 1