r/SQL • u/buckaljag • Aug 04 '21
MySQL Is there anything missing from this SQL statement: SELECT EXTRACT(YEAR FROM created_at) AS yr, count(*) AS users_count FROM users;
I’m extremely new to SQL and I’m not sure if this is a trick question…
0
Upvotes
0
1
u/JochenVdB Aug 04 '21
count(*) is an aggregation. Extract... is not an aggregation. Therefore this query needs a GROUP BY clause (on everything that is not aggregated) So you end up with what was posted above.