MySQL - Can I combine these 2 SQL statements? Combine JOIN and AVG?

You can do this using group by : select cars. *, brands. *, round(avg(car_ratings.

Rating)) as avg_rating from (cars inner join brands on brands. Br_id = cars. Brand_id) left join car_ratings on car_ratings.

Car_id = cars. Id where cars. Id = 185707 group by cars.Id Note that this is a MySQL extension to standard SQL in standard SQL you would need to list all of the selected fields in the group by clause.

You can do this using group by: select cars. *, brands. *, round(avg(car_ratings.

Rating)) as avg_rating from (cars inner join brands on brands. Br_id = cars. Brand_id) left join car_ratings on car_ratings.

Car_id = cars. Id where cars. Id = 185707 group by cars.Id Note that this is a MySQL extension to standard SQL; in standard SQL you would need to list all of the selected fields in the group by clause.

Select * , (select round(avg(rating)) from car_ratings where car_id = cars. Id) as avg_rating from cars join brands on brands. Br_id = cars.

Brand_id where cars. Id = 185707 But whether or not that represents an improvement is another question, best answered by seeing what query plan is being used.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions