sql - Mysql query 5 cheapest cars, multiple makes, from single table -
i have database of 750 vehicles, run query select no more 5 of cheapest vehicles each make & model , include in results.
my table fields fldyear, fldmake, fldmodel, fldretail etc.
for example output include 5 cheapest dodge 200 vehicles 25 in total, 5 cheapest honda accords 30 in total, 5 cheapest jeep cherokees 10 in total, , if there 2 volkswagon jettas, include them well. in above example output have total of 17 records.
i have played around sorts , group can't seem desired output.
just use variables:
select * ( select *, @row := if(fldmake = @make, @row := @row + 1, if(fldmake := @make, 1, 1) ) row yourcars cross join ( select @make := '', @row:=0 ) vars order fldmake, fldretail asc ) t t.row <= 5
Comments
Post a Comment