You need to fix the group by
clause to group by the actor not the star column. You need to fix the order by
to group by the aggregated column, not the original column:
SELECT a.id, a.name, sum( p.star = 1) AS stars
FROM actors a join playing p
on p.id_actor = a.id join
movies m
on p.id_movie = m.id
GROUP BY a.id, a.name
ORDER BY stars DESC;
Along the way, I fixed the from
so it uses proper join
syntax (with an on
clause). And changed the query so it returns all actors, even those who have never been the star.