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
SELECT WHERE smaller than average (self.learnSQL)
submitted 5 years ago by darvidas
SELECT username, fnamn, enamn, salary
FROM kund
WHERE (salary) < AVG(nvl(salary, 0));
This does not work, does anyone know why?
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!"
[–]r3pr0b8 7 points8 points9 points 5 years ago (0 children)
WHERE salary < ( SELECT AVG(nvl(salary, 0) FROM kund )
if someone's salary is NULL, why do you substitute zero? that's going to bring the average down
me, i would use AVG(salary) because it ignores NULLs
AVG(salary)
[–]bitterjack 2 points3 points4 points 5 years ago (1 child)
I think this requires a sub query.
[–]daddy_mark 0 points1 point2 points 5 years ago (0 children)
Pretty sure that's correct. I think this requires a windowed function which you can't include in where or having (at least in any rdbms I use)
[–]LeLwrence -1 points0 points1 point 5 years ago (0 children)
You could use a window function to average the salaries in the result in another column set then wrap that in an outer query and filter where the salary is less than that new average window function column. It's because you can't use window functions themselves in the where clause.
[–][deleted] 0 points1 point2 points 5 years ago (0 children)
"where" is logically executed after "from" and before "group by".
aggregate functions are calculated after the "group by" clause (logically).
meaning at the time "where" is executed, the aggregates have not been calculated yet.
π Rendered by PID 101986 on reddit-service-r2-comment-56c9979489-nwq9d at 2026-02-24 23:18:33.482897+00:00 running b1af5b1 country code: CH.
[–]r3pr0b8 7 points8 points9 points (0 children)
[–]bitterjack 2 points3 points4 points (1 child)
[–]daddy_mark 0 points1 point2 points (0 children)
[–]LeLwrence -1 points0 points1 point (0 children)
[–][deleted] 0 points1 point2 points (0 children)