Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Aggregating Year, Month and Week to date

531441Sep 13 2010 — edited Sep 13 2010
Good day,

I have a requirement that has led me thinking where I have to sum up sales value at three levels - year_to_date, month_to_date and week_to_date. While it is easy for me to represent the yearly and monthly version, I need to do a bit of logic to get the weekly variant.

The definitions of the functions are thus

year_to_date: Sum up the sales record from the january 1 to sysdate
month_to_date: sum up all sales record from 1 of the current month to sysdate
week_to_date: sum up all sales record from 12:00 am monday of the current week to sysdate

Is are they any such oracle sql functions to achieve this? I have googled and also search the oracle 10g R2 sql reference and could not find what I was looking for? Does anyone know of web reference where I could find a likely solution.


table definition
=============

id number(6)
trans_date date
sales_value number(15, 4)
receipt_no varchar2(20)


thanks
This post has been answered by Rob van Wijk on Sep 13 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2010
Added on Sep 13 2010
9 comments
3,537 views