Saturday, December 7, 2013

the product with the highest price


I have a
vehicle (vin, vmaker, vmodel, vyear)
customer (SSN, cname, cgender, ccity)
buyvehicle (BVSSN, BVVin, price, year)
I need a query that finds the vehicle with the highest sale price for each maker.
Please help!
example: Honda Civic $20000
Honda Accord $25000
BMW 3 Series $22000
BMW 5 Series $40000
the result should be:
Honda Accord
BMW 5 Series

SQL:
select v.vmaker, max(b.price) price
from vehicle v
left join buyvehicle b
    on v.vin = b.bvvin
group by v.vmaker

No comments:

Post a Comment