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 |
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2012-11-26 : 15:28:34
|
Hi All - I have the following table:[CODE]SKU PRICE123456 $10123456 $20123456 $30123457 $40123457 $50123457 $60[/CODE]My query to outputs a unique SKU based on the lowest price:[CODE]SELECT SKU, MIN(PRICE) FROM TABLE1GROUP BY SKU[/CODE]However, I need to perform a calculation on that aggregrate function. If a price is more than $10, it will deduct $10 off it. SQL does not allow calculation on the MIN(PRICE) function. How can I achieve this?Thanks! |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-11-26 : 15:33:44
|
Do the calculation inside the aggregate functionSELECT SKU, MIN(CASE WHEN PRICE > 10 THEN PRICE-10 ELSE PRICE END) AS AdjustedPriceFROM Table1GROUP BY SKU; Sunita. |
|
|
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2012-11-26 : 15:54:59
|
THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|
|
|
|
|