SELECT id,name,SUM(`lsa`) AS lst FROM
table_a AS sn,
table_b AS fb
WHERE sn.uid=fb.uid
AND COUNT(`lsa`)=6
GROUP BY sn.uid
ORDER BY SUM(`lsa`)
I have a query like this one, apparently the AND COUNT(lsa)=6 bit isn’t valid syntax. I’m quite lost.
What I’d like to achieve is a list, ordered by the sum of lsa, grouped by uid, only if there are 6 entries for that uid, i.e. in that “group”. How am I supposed to do that?
It is valid to filter by aggregates but that needs to go into the
HAVINGclause, not theWHEREso useinstead.