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 |
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2009-05-14 : 12:38:36
|
| Hi,Got this tableModel Price Column 3 Column 4 Column 5 etcA3 123 x x xA3 198 x x xA3 225 x x xA4 234 x x xA4 227 x x xA5 121 x x xA5 234 x x xA5 232 x x xI want to return 1 row for each distinct model with the lowest price. I believe I can user OVER PARTITION but not sure how. Thanks |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-05-14 : 12:41:11
|
select model, price, col3, col4, col5from (select model, price, col3, col4, col5, row_number() over (partition by model order by price desc) AS recID from table) as fwhere recid = 1 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-14 : 14:15:39
|
| [code]SELECT *FROM(SELECT Model, Price, [Column 3], [Column 4], [Column 5],MIN(Price) OVER (PARTITION BY Model) AS MinPriceFROM Table)tWHERE Price=MinPrice[/code] |
 |
|
|
|
|
|
|
|