I'm trying to update a table using a self join and aggregates.
For example, a table has the following columns:
store, item, price, lowprice, lowprice store
I need to populate lowprice
and lowprice store
.
The lowprice
would be:
Select item,min(price) group by item
The lowprice store
would be the store with the min(price)
for each item.
I'd love to be able to take it a step further as well. Say two stores offer an item at the same lowprice
. Then the value for lowprice store
would be 'store a/store b' but this part is less important.
I'm using SQL Server.