I just finished the Aggregate Functions topic in the Learn SQL Course and I am a little confused about the query below. Why doesn’t the ‘COUNT’ need to be told what to count?
WHERE url LIKE ‘%watch?v=dQw4w9WgXcQ’
GROUP BY 1
ORDER BY 2 DESC;
It is counting all rows with
And the records returned are filtered by the WHERE clause.
A little more explanation:
SELECT user, COUNT(*)
WHERE url LIKE '%watch?v=dQw4w9WgXcQ'
GROUP BY user
ORDER BY COUNT(*) DESC;
results in the number of times (the
COUNT(*) ) a user has posted that particular URL. You’re grouping by the user and ordering by the count of times they’ve posted that link.
Ah, that makes sense. Thanks.