Mysql, AVG and Count question
ID, rating_id , rating_num
33100, '4028', 2,
33099, '4041', 2,
33098, '1889', 4,
33097, '1889', 5,
33096, '4050', 2,
33095, '8578', 2,
33094, '8578', 4,
33093, '8578', 5,
33093, '8578', 5,
Guys 3 ques开发者_JS百科tions
1) How can i see which rating_id has received more than three counts of rating_num ? (Answer: 8578)
2) How can i see the average rating_num of each rating_id ?
3) How can i see the average rating_num of each rating_id WHICH received more than three counts of rating_num ? ( Answer: 4 )
Thanks for replying the classs attender of Mysql4dumbmies
1
select rating_id
from YourTable
group by rating_id
having count(*) > 3
2
select rating_id, avg(rating_num) as average_rating
from YourTable
group by rating_id
3
select rating_id, avg(rating_num) as average_rating
from YourTable
group by rating_id
having count(*) > 3
精彩评论