Getting the max(price) for each item ordered, given multiple different prices for any ordered item
If I have an items_ordered table that looks like this:
items_ordered
customerid order_date item quantity price
10330 30-Jun-1999 Pogo stick 1 28.00
10101 30-Jun-1999 Raft 1 58.00
10298 01-Jul-1999 Skateboard 1 33.00
10101 01-Jul-1999 Life Vest 4 125.00
10299 06-Jul-1999 Parachute 1 1250.00
10339 27-Jul-开发者_开发问答1999 Umbrella 1 4.50
10449 13-Aug-1999 Unicycle 1 180.79
And I want to get the max price for each distinct item in the table, given that an item could appear multiple times in this table with different prices, how would I do that, assuming that this doesn't work:
select item, max(price) from items_ordered;
Add a Group By and you're golden.
select item, max(price) from items_ordered group by item;
精彩评论