Sort 210 Discussions, By:
Please Login in order to post a comment
I think the question meant to say "Select a list of possible candidates for layoffs"
was thinking the same :D
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.
DIFFERENCE BETWEEN HAVING AND WHERE
1. WHERE is used to filter rows before grouping and HAVING is used to exclude records after grouping
2. HAVING can only be used if grouping has been performed using GROUP BY clause in the SQL query.
3. WHERE clause cannot contain aggregate function like COUNT(), SUM(), MAX(), MIN(), etc but HAVING clause may contain aggregate functions.
4. WHERE is used to impose filtering criterion on a SELECT, UPDATE, DELETE statement as well as single row function and used before group by clause but HAVING is always used after group by clause.
Hope this will clear your doubts between having and where. Let me know if you have any doubbts.
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
WHERE SALARY > 2000 AND MONTHS < 10
ORDER BY employee_id ASC;
super thank you
My solution for MySql :)
WHERE (salary >2000 AND months<10) ORDER BY employee_id ASC;
Here is Oracle solution from my HackerrankPractice repository:
WHERE Salary > 2000 AND Months < 10
ORDER BY Employee_id;
Feel free to ask if you have any questions :)
SELECT name FROM Employee WHERE salary > 2000 AND months < 10;
Simple solution ;-;