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 |
|
zeeshan13
Constraint Violating Yak Guru
347 Posts |
Posted - 2006-06-12 : 14:42:16
|
| Hi All,I have a table with the following fields.Date(Datetime),ZoneID(varchar), ProductID(varchar),Price(float),Cost(float),Units(big int)Each record tells the price,cost,units of a product sold in a particular zone on a particular date.A product may or may not sold on a particular date.I want to see the most recent (most latest date available) information of each product in each zone.I want the following fields:ZoneID,ProductID, MostRecentPrice, MostRecentCost, MostRecentUnits, DateWhere Date will be the most recent date on which that product (in that particular zone) was sold.Thanks a million in adavance.-Zeeshan |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
PSamsig
Constraint Violating Yak Guru
384 Posts |
Posted - 2006-06-13 : 02:26:05
|
| [code]SELECT t.ZoneID ,t.ProductID ,t.Price AS MostRecentPrice ,t.Cost AS MostRecentCost ,t.Units AS MostRecentUnits ,t.DateFROM table tINNER JOIN ( SELECT ZoneID, ProductID, MAX(Date) AS MaxDate FROM table o GROUP BY ZoneID, ProductID ) AS dt ON t.ZoneID = dt.ZoneID AND t.ProductID = dt.ProductID AND t.Date = dt.MaxDate[/code]-- This one's tricky. You have to use calculus and imaginary numbers for this. You know, eleventeen, thirty-twelve and all those. |
 |
|
|
|
|
|
|
|