Cannot pin down the error of my solution


  • 0
    T
    SELECT  d.Name As Department, E1.Name As Employee, E1.Salary 
    FROM Employee E1 INNER JOIN Department d ON E1.DepartmentId = d.Id 
    WHERE 3 > (SELECT COUNT (DISTINCT (E2.Salary)) 
    FROM Employee E2 WHERE E2.DepartmentId = E1.DepartmentId AND E2.Salary > E1.Salary);
    

    Can any one find the error of my solution? I feel I almost exactly copied someone's right answer (which I tested and passed), but still not correct.
    Please help, thanks!


  • 0

    Remove the space after COUNT.

    (Also, to help others help you, please include input/output/error. Well, since this is a syntax error, the error would've sufficed.)


  • 0
    T

    Thank you! That's really it! I'm quite new to SQL and didn't know that it's so strict with space. I will take your advice to include error next time. Thank you again!


  • 0

    I actually didn't know it's so strict, either :-)

    I btw copy&pasted it into the MySQL Workbench on my PC, which helped a lot to locate the problem ... it red-underlined the ( after COUNT.


  • 0
    R

    I was just curious - are you actually able to debug leetcode SQL problems on your MySQL Workbench? Don't you need to do a lot of work like set up appropriate tables, insert rows, etc.?
    I'm asking since I find debugging SQL on leetcode very tedious since they don't accept custom test cases. Thanks!


  • 0

    @rohan99
    I actually don't remember... I do SQL problems so rarely. But I think I did create a table with some rows once. In this case it wasn't necessary, though, as the workbench showed me the syntax error without needing the table.


  • 0
    R

    alright, thanks!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.