http://www.javashuo.com/article/p-zzkzqyon-cm.htmlmysql
https://blog.csdn.net/zheng0518/article/details/10449549spring
就是统计 评价当前电影 各星星等级 的人数sql
问题:搜mysql 同一字段 相同的值 的条数springboot
找到解决办法的博客:http://www.javashuo.com/article/p-szyrnqlz-kw.html.net
我最后写出的语句是这样的:3d
select m.id,m.name,COALESCE(startb.one,0) as onestar,COALESCE(startb.two,0) as twostar,COALESCE(startb.three,0) as threestar,COALESCE(startb.four,0) as fourstar,COALESCE(startb.five,0) as fivestar from movie m LEFT JOIN (SELECT id,star,movie_id,sum(case star when 1 then 1 else 0 end) as one, sum(case star when 2 then 1 else 0 end) as two,sum(case star when 3 then 1 else 0 end) as three ,sum(case star when 4 then 1 else 0 end) as four , sum(case star when 5 then 1 else 0 end) as five from score where movie_id =5) as startb on startb.movie_id = m.id