+ 1

MySQL command!

You have a table with employee payment, you have to select employee with less payment than average. I tried the following command: SELECT username FROM users WHERE payment < AVG(payment) ERROR #1111 - invalid use of group function

23rd Mar 2018, 1:39 PM
Akib
Akib - avatar
5 Respostas
+ 7
SELECT username FROM users WHERE payment < (SELECT AVG (payment) FROM users) ?
23rd Mar 2018, 1:46 PM
Geo
Geo - avatar
+ 4
Not to my knowledge.
23rd Mar 2018, 1:49 PM
Geo
Geo - avatar
+ 1
Well, just found the answer. That would be SELECT username FROM users WHERE payment<(SELECT AVG(payment) FROM users) **IF anyone knows a better /easier way let me know.
23rd Mar 2018, 1:45 PM
Akib
Akib - avatar
+ 1
Yah, I found it too. Any easier command?
23rd Mar 2018, 1:48 PM
Akib
Akib - avatar
+ 1
SELECT username FROM users WHERE payment<(SELECT AVG(payment) FROM users) **This is the simplest command you can find out there unless you want to group the observations and then use the HAVING clause.
21st Jul 2020, 11:28 AM
Vaibhav Sharma
Vaibhav Sharma - avatar