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