Group by aggregate function question with pics, please help!

Hello, I’m a little confused by the group by exercise in aggregate functions.

how come when you do:
select category, sum(downloads) from fake_apps;
It shows the total downloads (for all categories I think 3,322,760) but it lists it next to ONLY productivity under category? I thought that if you select category it would list all the different categories, not just “productivity”?

question 2: once you do
select category, sum(downloads)
from fake_apps
group by category;
then it shows all the different categories, including productivity which had 117,811 downloads but in the previous pic was showing 3,322,760? maybe I’m not understanding. it won’t let me post a second picture.

thank you very much!!

Hello @aisha4601294631, welcome to the forums!

This is because you are only using one row, to show the SUM(downloads); which shows the total downloads for all of the categories. productivity must just be the first category, so that’s what get shown next to SUM(downloads).

Once you use GROUP BY, it spreads out the count of downloads into the different categories, so productivity is now shown next to, not the sum of all categories as in the last question, but only the sum of the downloads for it.

I hope this helps!


Thank you SOOOO much!!! I checked and productivity was indeed the first category, so that makes sense. My only question is regarding what you mean when you say that you are only using one row to show the sum(downloads)? thank you, sorry for the dumb question @codeneutrino

When you write:

SELECT SUM(downloads)
FROM fake_apps;

You’ll get one row:


So, when you add:

SELECT category, SUM(downloads)
FROM fake_apps;

You will still only get the one row required to show SUM(downloads), but there will also be the first item from category in the category column:

  category  | SUM(downloads)
Productivity|   3322760

@codeneutrino you are literally the best, thank you! I was confused because whenever I do select category, it lists all the categories. I thought combining it with sum(downloads) would still show all categories and that one sum value. I’m assuming all categories did not appear due to the fact that we added sum(downloads), so only one row of categories ended up showing because the sum is only one value?

1 Like

Exactly! (This always confuses me as well).

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.