| Author |
Topic  |
|
|
de9625
Starting Member
17 Posts |
Posted - 12/12/2002 : 06:55:17
|
I need a query that gets the value from the latest date in a period, in this case a week. The actual period is between about nine weeks.
The table contains a number of transactions for each day, so I want to do a sum(transaction_value) for the last day in the week.
Recordset with the result:
Field 1(sum of value for the last day), Field 2 (year + week number) ---------------------------------------------------------------- 1293243, 200249 324234243,200250 324234324,200251 243098324,200252 45354345,200301 etc....
Hmm, I dont know where to start. I know I have do a group by for the year and week but not how to get them sum of transactions for the last day in every week. Cursors are not an option in this case :-(
|
|
|
Page47
Flowing Fount of Yak Knowledge
USA
2878 Posts |
Posted - 12/12/2002 : 07:18:11
|
Have you tried the sum() aggregate function?
(how bout you post some ddl and sample data so we can have a clue what you are talking about)
Jay White {0} |
 |
|
|
de9625
Starting Member
17 Posts |
Posted - 12/12/2002 : 07:41:40
|
I think I found a solution: The datepart function has probably not correct syntax it should work something like that.
SELECT (SUM(trans_value)/1000) AS value_SUM, Datepart(transDate,YEAR)+ Datepart(transDate,WEEK) AS PERIOD, transDate FROM table1 WHERE transDate IN ( SELECT MAX(transDate) AS transDate FROM table1 WHERE transDate between 20021206 and 20030131 GROUP BY Datepart(transDate,YEAR)+ Datepart(transDate,WEEK) AS PERIOD )
GROUP BY Datepart(transDate,YEAR)+ Datepart(transDate,WEEK) AS PERIOD,transDate ORDER BY transDate
|
 |
|
| |
Topic  |
|
|
|