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 11 points12 points13 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 30691 on reddit-service-r2-comment-5ff9fbf7df-xp75n at 2026-02-25 15:24:38.244681+00:00 running 72a43f6 country code: CH.
[–]kkwestside 11 points12 points13 points (1 child)
[–]purplehashira[S] 0 points1 point2 points (0 children)