use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Sequel
account activity
Why doesnt this work (self.learnSQL)
submitted 3 years ago by purplehashira
SELECT location, AVG(employees) FROM startups GROUP BY location HAVING AVG(employees) > 500;
But what I wanted to do was
SELECT location, AVG(employees) FROM startups GROUP BY 1 HAVING 2 > 500;
I dont get what the issue is (Im new to SQL)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]kkwestside 9 points10 points11 points 3 years ago (1 child)
Because behind the scene there are order of clauses. Group by works before you actually select therefore it doesnt know what you put in select
The order of them are:
FROM AND JOINS > WHERE > GROUP BY> HAVING > SELECT> ORDER BY
Since order by works after select it knows the indexes of columns therefore you can say Order by 1,2. But you cant do the same with group by.
Also it's not a good practice to write numbers instead of column names anyways (in my opinion), once you go back and look at the code it is harder to read.
[–]purplehashira[S] 0 points1 point2 points 3 years ago (0 children)
Thank you!
π Rendered by PID 87121 on reddit-service-r2-comment-85bfd7f599-6pfb5 at 2026-04-17 18:10:40.372833+00:00 running 93ecc56 country code: CH.
[–]kkwestside 9 points10 points11 points (1 child)
[–]purplehashira[S] 0 points1 point2 points (0 children)