Hi,
Wondering where I can find a reference document for clause order rules? While working through the Hacker News project, I found this on the cheatsheet for the Aggregate Functions lesson:
" The GROUP BY
clause can come after FROM
or WHERE
but must come before any ORDER BY
or LIMIT
clause.
The given query will count the number of movies per rating."
Tried to run the following:
“SELECT strftime(‘%H’, timestamp) WHERE timestamp IS NOT NULL AS ‘Publication Hour’,
ROUND(AVG(score), 1) AS ‘Average Score’,
COUNT(*) AS ‘Number of Stories’
FROM hacker_news
GROUP BY 1
ORDER BY 1;”
But learned (from the Hint Section), that the WHERE timestamp IS NOT NULL needed to be positioned as follows:
“SELECT strftime(‘%H’, timestamp) AS ‘Publication Hour’,
ROUND(AVG(score), 1) AS ‘Average Score’,
COUNT(*) AS ‘Number of Stories’
FROM hacker_news
WHERE timestamp IS NOT NULL
GROUP BY 1
ORDER BY 1;”
Learn SQL: Queries Cheatsheet | Codecademy
Learn SQL: Aggregate Functions Cheatsheet | Codecademy
Aggregate Functions | Codecademy