When I am trying to do this
select first_name from employees
group by salary,first_name
having salary between 0 and 4800
I am getting 49 records
When I am trying to do this I am getting no results
select first_name from employees
group by salary,first_name
having salary between 0 and (max(salary)/5)
Here select max(salary)/5 from employees fetches : 4800
This is simple but I don’t know what silly mistake I am doing
In this statement
you’re grouping by salary and first_name, which is likely grouping by just one row. You’re essentially looking for X that’s between 0 and X/5, which is likely to return no results.
In this statement
you’re grouping by nothing, so you get the max salary of everyone.
I think this
is what you’re looking for