Mysql,AVG和Count问题

时间:2011-02-09 17:29:26

标签: mysql

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,

伙计3个问题

1)我怎样才能看到哪个rating_id收到了三个以上的rating_num? (答案:8578)

2)我怎样才能看到每个rating_id的平均rating_num?

3)我怎样才能看到每个rating_id的平均rating_num收到三个以上的rating_num? (答案:4)

感谢您回复Mysql4dumbmies的课程参与者

1 个答案:

答案 0 :(得分:0)

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