Re: getting sum of units sold in preceeding weeks
From: Vishal Parkar (REMOVE_THIS_vgparkar_at_yahoo.co.in)
Date: 05/11/04
- Previous message: Nikhil: "getting sum of units sold in preceeding weeks"
- In reply to: Nikhil: "getting sum of units sold in preceeding weeks"
- Next in thread: Nikhil: "Re: getting sum of units sold in preceeding weeks"
- Reply: Nikhil: "Re: getting sum of units sold in preceeding weeks"
- Reply: Nikhil: "Re: getting sum of units sold in preceeding weeks"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 11 May 2004 11:32:37 +0530
hi nikhil,
pls post sample data, table structure to get correct results. However you
can have query as follows, replace dt_column with the name of the date
columns you have and sold_units with the "units sold" column of your table.
select
select sum(case when dt_column >= dateadd(dd, -7, {fn current_date()} )
and dt_column <= getdate() then sold_units else 0 end) 'last week',
sum(case when dt_column >= dateadd(dd, -14, {fn current_date()} ) and
dt_column < dateadd(dd, -7, {fn current_date()} ) then sold_units else 0
end) '2nd last week'
/*
... so on, add sum(CASE... statements to above query till the required
date.
*/
from
<table_name>
--
Vishal Parkar
vgparkar@yahoo.co.in | vgparkar@hotmail.com
- Previous message: Nikhil: "getting sum of units sold in preceeding weeks"
- In reply to: Nikhil: "getting sum of units sold in preceeding weeks"
- Next in thread: Nikhil: "Re: getting sum of units sold in preceeding weeks"
- Reply: Nikhil: "Re: getting sum of units sold in preceeding weeks"
- Reply: Nikhil: "Re: getting sum of units sold in preceeding weeks"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|