i to get "Average" with "GroupBy" in mysql
id config_id question rating
1 68 lorem1 3
2 68 lorem2 5
3 69 lorem3 5
4 68 lorem1 NULL
i want to get average rating of every "config_id" ( not repeat ) i tried with following code,But not working for me
SELECT AVG(rating) AS AVERAGE
FROM (SELECT config_id, AVG(rating) AS avg_rating
FROM "nps_ans" GROUP BY config_id) A
;
SELECT AVG(rating) AS AVERAGE
FROM nps_ans GROUP BY config_id;
if you need the average per config_id irrelevant of the question,
select config_id,AVG(rating) AS average from nps_ans group by config_id;
or
select question,config_id,AVG(rating) AS average from nps_ans group by config_id,question;
if you need the average rating per config and per question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.