解决方案 »

  1.   

    补充下,haoping  就是好评所占的比例,同理为中评,差评的比例
      

  2.   

    select target_id,count(case when commnet_level=1 then 1 else null end )*1.0/count(commnet_level) [haoping]
    from tb
    group by target_id后面两个同理
      

  3.   

    select target_id,
             sum(case when comment_level=1 then 1 else 0 end)*1.0/count(*) as haoping,
             sum(case when comment_level=2 then 1 else 0 end)*1.0/count(*) as zhongping,
             sum(case when comment_level=3 then 1 else 0 end)*1.0/count(*) as chaping
    from 评论表
    group by target_id