I don't understand what is the mistake here why it is not working (Oracle DB)
https://www.hackerrank.com/challenges/binary-search-tree-1/problem?isFullScreen=true
This is a question of hackerrank
SELECT N,
(case
when P IS NULL then 'Root'
else
when (SELECT COUNT(*) FROM BST WHERE P=B.N) > 0 then 'Inner'
else 'Leaf'
end
end ))
FROM BST AS B ORDER BY N;
First I thought that outer query is used in inner query so it won't work. But if it is working for MySQL then it should work for Oracle also.
This below code is for MySQL and it was working
SELECT N, IF(P IS NULL,'Root',IF((SELECT COUNT(*)
FROM BST WHERE P=B.N)>0,'Inner','Leaf'))
FROM BST AS B ORDER BY N;
caseexpression. That is not necessary (as Barbaros Ozhan has shown), but if you do use a nestedcaseexpression (which is not wrong, it's just unnecessary) as you do, you are missing the keywordcasein the inner expression - right beforewhen (SELECT COUNT.....(As B.O. also said, you have an invalid use ofaslater in the query.)caseis not necessary, can you tell me what is the simplified version of this query. Though Barbaroz Ozhan has given a great solution. I just want to know if you have another approach