每周查找总计

时间:2011-12-15 09:52:51

标签: sql oracle plsql oracle11g

我有一个包含tabledate列的表total

如何将过去20周内每周sum列的total汇总到sysdate

2 个答案:

答案 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