Add function in SQL
<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

We used the
SELECT price, COUNT(*) FROM fake_apps GROUP BY price;
function because we wanted to count all rows and wanted to group by price. So when we want to add just the values of the rows of the downloads column, why can’t I do the following:
select * from fake_Apps
sum (downloads);

why does it have to be select Sum (downloads) from fake_apps; ?

GROUP BY is basically a way of categorizing how the function, COUNT in this case, is being ran. If we ran COUNT(*) without GROUP BY would just return a count of all the rows. When we use GROUP BY price we can see a count of all the rows categorized by price. So all the free, 0.99, 1.99 etc…

SUM(downloads) is different from GROUP BY because SUM(downloads) is telling SQL what data to pull whereas GROUP BY is telling SQL how to sort it and pull it.

Hopefully that makes sense, if not I can try and explain it more.

could you clarify what * is used for. Is it referring to the usage of all rows or all columns?

it mentions that * is a special wildcard character that we have been using. It allows you to select every column in a table without having to name each one individually.

But in other instances * seems to refer to all rows.

* is a wilecard meaning everything. If we run SELECT * FROM fake_apps we are saying grab every column from the fake_apps table. When we use COUNT(*) we are telling it to count every row. Context is everything, in a select statement we are choosing which columns to select data from. When we use aggregate functions such as COUNT and SUM we are dealing with rows.

1 Like

That makes a lot of sense. That disclaimer should be created inside the lesson. I think many may be confused by the same point.

That’s a good point! Unfortunately the SQL lessons are rather poorly written. It’s kind of disappointing because so many of Codecademy’s lesson are great.

1 Like

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