Skip to content
Advertisement

Display Average Rating by Id with Count of Ids Mysql

I have an MYSQL table, where I want to get the average rating with a count of product id. Here is the sample of the table.

JavaScript

I have worked on this piece of code but didn’t get the desired result.

JavaScript

which gives me the result as, average rating (number of ratings for the same product Id)

  1. 3(3)
  2. 4(2)
  3. 4(2)

where I want results to be print as, average rating (number of products ids with the same Rating)

  1. 3(1)
  2. 4(2)

how can I attain the above results

Advertisement

Answer

If I understand, then you want two levels of aggregation:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement