Re: getting sum of units sold in preceeding weeks
From: Nikhil (anonymous_at_discussions.microsoft.com)
Date: 05/12/04
- Previous message: MUSTAFA: "DEC TO HEX CONVERSION WHILE IMPORTING"
- 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: Wed, 12 May 2004 00:41:09 -0700
hi there...thanks for the help so far....
wosh..i finally got it.....the query does give me week wise sale...for all items for the past 12 weeks..the way i wanted....but now in addition to this..i want two more columns...
1. average
2. standard deviation
for each item...i want the average of all 12 weeks and the standard deviation of all 12 weeks in two adjoining columns...
pray tell me how do i go about with this....
regards
Nikhil
----- Vishal Parkar wrote: -----
>>can i have the same in diff columns...e.g. the table column heading would
be
yes possible, you only have to add group by clause. See following example
--sample data
create table tableA
(dt_column datetime,
sold_units int,
itemid int)
insert into tableA values(getdate() ,3, 1)
insert into tableA values(getdate() -1 ,3, 1)
insert into tableA values(getdate() -15,3, 1)
insert into tableA values(getdate() ,3, 2)
insert into tableA values(getdate() -15, 43, 2)
--required query
select itemid,sum(case when dt_column >= dateadd(dd, -7, {fn
current_date()} )
and dt_column <= getdate() then sold_units else 0 end) 'week1',
sum(case when dt_column >= dateadd(dd, -15, {fn current_date()} ) and
dt_column < dateadd(dd, -7, {fn current_date()} ) then sold_units else 0
end) 'week2'
from
tableA
group by itemid
--
Vishal Parkar
vgparkar@yahoo.co.in | vgparkar@hotmail.com
- Previous message: MUSTAFA: "DEC TO HEX CONVERSION WHILE IMPORTING"
- 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
|
|