I am following this task
Then, we want to add these users’
score s together and divide by the total to get the percentage.
Add their scores together and divide it by the total sum. Like so:
SELECT (1.0 + 2.0 + 3.0) / 6.0;
So, is Hacker News dominated by these users?
HERE IS THE HINT: SELECT (517 + 309 + 304 + 282) / 6366.0;
I do not want to manually type the numbers for the division so I used these syntax to get Sum
of Score from the group by
WITH each_s AS ( SELECT user, SUM(score) as each_score
GROUP BY user
HAVING each_score > 200), TOTAL AS( SELECT SUM(score) FROM hacker_news)
SELECT SUM(each_score) FROM each_s;
The final syntax gives: 1412 is correct
Now I need to take 1412 to divide for Total score (6366) BUT I do not want to manually type 6366 in
Syntax to get the total is SELECT SUM(score) FROM hacker_news;
Is there anyway to do this math automatically and got 22% as result INSTEAD OF typing 517 + 309 + 304 + 282 and 6366?