Mian Ashar Mian Ashar - 10 months ago 56
MySQL Question

Selecting average value from multiple rows

I have 2 columns in mysql database i.e. totalRating and ratingDate. There exists multiple values of totalRating against on date e.g. there can be 5 totalRatings on date 2016-08-29, 4 on 2016-08-30. I am using ChartJs to show a graph of totalRating and ratingDate. I want to take the average of totalRatings of a single date and plot it on graph i.e. one totalRating for one date. I am using PHP for the backend. Can somebody help me with the queries?


Using below query you can find average rating for all dates.

select AVG(totalRatings) as avgRating, date from YOUR_TABLE group by date;