mysql - Get different min and max values based on column from three joined tables -
i want figure out earliest year , latest year car manufacturer making cars. have following 3 tables. year associated particular model need join 3 tables associate each year make. want select min , max year of each make.
make table
make_id make_name 1 acura 2 alfa romeo 3 aston martin
model table
model_id make_id model_name 10 1 integra 11 1 mdx 12 1 legend 13 2 milano 14 2 quadrifoglio 15 3 rapide
year table
year_id model_id year 100 10 1996 101 11 2001 102 12 1992 103 13 1989 104 14 1974 105 15 2013
i want following result:
make_id make_name lowest_model_year highest_model_year 1 acura 1996 2001 2 alfa romeo 1974 1989 3 aston martin 2013 2013
try this:
select make.make_id make_id, make.make_name make_name, min(`year`) lowest_model_year, max(`year`) highest_model_year make left join model on model.make_id = make.make_id left join year on year.model_id = model.model_id group make.make_id
Comments
Post a Comment