SQL group by problem
I have a SQL group by problem. My table has the following form.
Cust_id. Price_id Price.
----------------------------
1. 556. 5000.
-----------------------------
2. 654. 600.
2. 432. 487.
2. 546. 500.
---------------------------
3. 455. 200.
3. 877. 143.
3. 123. 879.
Now when I run this query:
Select cust_id, max(price) as max, min(price) as min.
From table.
Group by cust_id.
I get.
Cust_id. Max. Min.
1. 5000. 5000.
2. 600. 487.
3. 879. 143.
But what I really want is not the max and min price but the price_id associated with the price.
So the results would be.
Cust_id. Max. Min.
1. 556. 556.
2. 654. 432.
3. 123. 877.
I am at a loss for how to do this. I think that the above query would be a sub query of some sort but that is as far as I got.