I just finished the Welp project (from the Analyze Data with SQL Skill Path), yay!
This was my solution for the last step:
WITH average_rating AS ( SELECT AVG(average_rating) as avg_rating FROM places ), bad_ratings AS( SELECT id, username, place_id, review_date, rating, note, average_rating.avg_rating FROM reviews CROSS JOIN average_rating WHERE rating < avg_rating ), bad_ratings_per_user AS ( SELECT username, COUNT(id) as "num_of_bad_ratings" FROM bad_ratings GROUP BY username ) SELECT username, MAX(num_of_bad_ratings) as "bad_ratings" FROM bad_ratings_per_user;
However, I feel like it’s kind of…unnecessarily long, and that annoys me
Also, the hint said I would probably have to use
ORDER BY and
LIMIT, but I only used
GROUP BY so there’s probably another way to solve this that I’m not seeing.
Any help would be appreciated