find total sales for the whole last week [message #446291] |
Sun, 07 March 2010 09:49  |
aijaz786
Messages: 91 Registered: February 2010
|
Member |
|
|
I have two columns in table
sales_date
sales_amount
I need to find total sales for the whole last week.
Today is current week i.e. 1 (March 1, 2010 and March 7, 2010)
I need to find total_sales for the last week (i.e. Feb 22, 2010 to Feb 28, 2010)
I am unable to create logic for the same. I will appreciate for all your cooperation.
Thanks
|
|
|
Re: find total sales for the whole last week [message #446292 is a reply to message #446291] |
Sun, 07 March 2010 10:00   |
 |
Michel Cadot
Messages: 68737 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
SQL> select trunc(sysdate,'IW') cur_wk,
2 trunc(sysdate,'IW')-7 start_prev_wk,
3 trunc(sysdate,'IW')-1 end_prev_wk,
4 to_char(sysdate,'IW') cur_wk,
5 to_char(sysdate-7,'IW') prev_wk
6 from dual
7 /
CUR_WK START_PREV END_PREV_W CU PR
---------- ---------- ---------- -- --
01/03/2010 22/02/2010 28/02/2010 09 08
1 row selected.
Regards
Michel
[Updated on: Sun, 07 March 2010 10:01] Report message to a moderator
|
|
|
Re: find total sales for the whole last week [message #446327 is a reply to message #446291] |
Sun, 07 March 2010 22:22   |
aijaz786
Messages: 91 Registered: February 2010
|
Member |
|
|
Thanks, Michael.
Similar to this, If I need to find total sales for the entire previous month then I am using the following query but it is not giving right results.
i.e. right March is in progress, I need to find total sales for Feb 2010. When I will be in April, I will need total sales for March 2010.
select trunc(sysdate,'MM') curr_month,
trunc(sysdate,'MM')-30 start_prev_month,
trunc(sysdate,'MM')-1 end_prev_month
from dual
Please advise.
Thanks.
|
|
|
|
|