Mian Ashar Mian Ashar - 3 months ago 7
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?

Answer

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

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