Re: getting sum of units sold in preceeding weeks
From: Nikhil (anonymous_at_discussions.microsoft.com)
Date: 05/11/04
- Next message: Nikhil: "require purchase details over diff months"
- Previous message: Vishal Parkar: "Re: getting sum of units sold in preceeding weeks"
- In reply to: Vishal Parkar: "Re: getting sum of units sold in preceeding weeks"
- Next in thread: Vishal Parkar: "Re: getting sum of units sold in preceeding weeks"
- Reply: Vishal Parkar: "Re: getting sum of units sold in preceeding weeks"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 11 May 2004 03:06:04 -0700
Well i did get that query..right sort off...
want one more help...
can i have the same in diff columns...e.g. the table column heading would be
item - week1 - week2 - week3
regards
Nikhil
----- Vishal Parkar wrote: -----
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
- Next message: Nikhil: "require purchase details over diff months"
- Previous message: Vishal Parkar: "Re: getting sum of units sold in preceeding weeks"
- In reply to: Vishal Parkar: "Re: getting sum of units sold in preceeding weeks"
- Next in thread: Vishal Parkar: "Re: getting sum of units sold in preceeding weeks"
- Reply: Vishal Parkar: "Re: getting sum of units sold in preceeding weeks"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|