You are viewing a single comment's thread. Return to all comments →
From my HackerRank solutions.
SELECT name FROM Employee
WHERE salary > 2000 AND months < 10
ORDER BY employee_id;
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 .
"salary is the their monthly salary" as it says in the problem.
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.
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:-
WHERE months < 10
AND salary > 2000;
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".
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)
salary > 2000 AND months < 10
The question asks to order employee id ascending.
ORDER BY employee_id ASC;
ASC = Ascending
DESC = Descending