如何制作按月分组的年度报告?

发布于 12-02 01:19 字数 261 浏览 0 评论 0原文

我使用下面的查询按月列出交易数量。有谁知道我怎样才能按年份列出。这意味着查询返回我全年除当月之外的所有交易。

也就是说,如果今天是 2011 年 8 月 29 日,我需要一份按月份分组的年度报告,直到 7 月份(因为 8 月份不完整)

select to_char(date,'MONTH YYYY'), sum(number_of_transactions)
from header
group by date
order by date

I am using the below query to list the number of transactions by month. Does anyone know how can I list by year too. This means that the query returns all my transactions for the whole year except the current month.

That is if today it is the 29th August 2011 I need a yearly report grouped by month till the month of July (since august is not complete)

select to_char(date,'MONTH YYYY'), sum(number_of_transactions)
from header
group by date
order by date

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无妨#2024-12-09 01:19:45
select to_char(trunc(date,'yyyy'),'YYYY') as year, sum(number_of_transactions)
from header
where date < trunc(sysdate, 'mm')
group by trunc(date,'yyyy')
order by year
select to_char(trunc(date,'yyyy'),'YYYY') as year, sum(number_of_transactions)
from header
where date < trunc(sysdate, 'mm')
group by trunc(date,'yyyy')
order by year
两仪2024-12-09 01:19:45

这是你需要的吗?

SELECT TO_CHAR(date, 'YYYY'), SUM(number_of_transactions)
FROM header
GROUP BY TO_CHAR(date, 'YYYY')

Is this what you need?

SELECT TO_CHAR(date, 'YYYY'), SUM(number_of_transactions)
FROM header
GROUP BY TO_CHAR(date, 'YYYY')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文