So I have a table, and I'm trying to get the SUM(activity_weight) WHERE activity_typeid is unique.
Each competition has an unlimited amount of activity_typeid's.
As you can see in my code below, I wonder if there is some SQL function to find the SUM of something WHERE the id is unique for example?
THANKS FOR ANY HELP IN ADVANCE!
I've attached a photo of my table and desired output below
SELECT a.userid, u.name, u.profilePic ,
SUM(activity_weight) AS totalPoints ,
//sum the points when the activity_typeid is unique and make an extra column for each of those sums
SUM(CASE WHEN activity_typeid //is unique// THEN activity_weight ELSE NULL END) AS specific_points ,
FROM activity_entries a INNER JOIN users1 u ON u.id = a.userid
WHERE competitionId = '$competitionId' GROUP BY a.userid ORDER BY totalPoints