Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Adria
Starting Member
2 Posts |
Posted - 2003-05-02 : 08:08:21
|
| Hi.so let me explain what i have:structure:date,product code, group, sales(quantity)....would like to gethow many sales were made for each product grouped by weeks..so perfect would be if i could get something like thisgroup 1 January week1 product code sum(sales) ........... week2............any ideas? |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2003-05-02 : 09:01:51
|
| SELECT date, productcode, sum(sales)FROM MyTableGROUP BY DATEPART(wk, date)------Look at the CONVERT function in BOL to pull the month and week out of date.Sam |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-05-02 : 09:26:56
|
| Sam -- that actually won't work. you are selecting date but not grouping by it:SELECT date, productcode, sum(sales) FROM MyTable GROUP BY DATEPART(wk, date) Based on your full specs (including grouping by the Group column) what you want to do is something like this:select [Group], Year(date), Month(date), datepart(wk,date) as Week, productcode, sum(sales)from MyTablegroup by [Group], Year(date), Month(date), datepart(wk,date), productCodeorder by code, year(date), month(date), datepart(wk,date), productcode- Jeff |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2003-05-02 : 09:34:43
|
| JeffThat will return week of year I think he wants week of month see my post above. |
 |
|
|
|
|
|
|
|