We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
hope ur code is like "select name,salary,months from employee having salary >2000 and months < 10 order by employee_id;" sal,months are not expected in output.
HAVING is used with GROUP BY and not ORDER BY.
In the question you have been asked to sort according to the employee_id. This can be done by using ORDER BY.
shall we need to add command "ORDER BY employee_id" here.
by default table itself, data is displayed in order of Employee ID.
Not only that, it does't mention in question also.
Employee Salaries
You are viewing a single comment's thread. Return to all comments →
MySQL solution
From my HackerRank solutions.
Let me know if you have any questions.
question says salary should be greater than 2000 PER MONTH. your query check if it is greater than 2000 or not . explain please.
"salary is the their monthly salary" as it says in the problem.
HackerRank solutions.
Why does it give wrong answer if I use HAVING clause instead of WHERE clause?
paste your code here and we can take a look.
hope ur code is like "select name,salary,months from employee having salary >2000 and months < 10 order by employee_id;" sal,months are not expected in output.
HAVING is used with GROUP BY and not ORDER BY. In the question you have been asked to sort according to the employee_id. This can be done by using ORDER BY.
Oracle :
SELECT name FROM Employee WHERE salary > 2000 and months< 10 ORDER BY employee_id asc;
Other with MS SQL Server, I don't think you can order by employee_id if employee_id is not in you select!
This is my MySQL Query:-
shall we need to add command "ORDER BY employee_id" here. by default table itself, data is displayed in order of Employee ID. Not only that, it does't mention in question also.
yes your query does pass the testcase
The question states to " Sort your result by ascending employee_id".
HackerRank solutions.
We need to add "Order By employee_id" because it is specified that we need ascending order.
What if months = 9 and salary = 9000
The line
salary > 2000 AND months < 10
will match that (as in it will be true)HackerRank solutions.
The question asks to order employee id ascending. ORDER BY employee_id ASC;
ASC = Ascending DESC = Descending