I need help with the code below. I am hoping to find the averages and counts for each distribution group of numbers of fans. When I run the code I am only seeing the averages for all of the users and the group is appearing as the first group of 0-20 fans.
Thank you!
SELECT
CASE
WHEN U.Fans >0 AND U.Fans <=20 THEN ‘0-20 Fans’
WHEN U.Fans >20 AND U.Fans <=40 THEN ’21-40 Fans’
WHEN U.Fans >40 AND U.Fans <=60 THEN ’41-60 Fans’
WHEN U.Fans >60 AND U.Fans <=80 THEN ’61-80 Fans’
END AS ‘Distribution of Fans’,
AVG(U.Review_Count) AS Average_Review_Count,
AVG(U.Average_Stars) AS Average_of_Average_Stars,
COUNT(R.Useful = 1),
COUNT(R.Funny = 1),
COUNT(R.Cool = 1)
FROM User AS U
INNER JOIN Review AS R ON U.Id = R.User_Id
GROUP BY ‘Distribution of Fans’
I tried to group by ‘Distribution of Fans’ in hopes that I would be able to see averages/counts for each group of fans I created in the Case/When statements.
user25022273 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.