Analyze Data with SQL - How to Hack Hacker News - Step 4

The project asks you to get the percentage obtained from dividing the sum of the scores of all users with a total score of over 200 by the total sum of the scores of all users.
I think I went a little overboard in writing my code:

 SELECT ((top_users_total * 1.0)/ total) as 'Top User Percent of Score'
 FROM (SELECT SUM(top_user_total) AS top_users_total
      FROM (SELECT user, SUM(score) AS top_user_total
          FROM hacker_news
          GROUP BY 1
          HAVING top_user_total > 200)),
      (SELECT SUM(score) AS total
      FROM hacker_news);

Looks like they just wanted a query using the actual numbers obtained in previous queries:

SELECT (517 + 309 + 304 + 282) / 6366.0;

Oh well. It was more work, but I feel like I learned a lot, and Iā€™m definitely getting the hang of this.

1 Like