일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 역행자
- 최강의 인생
- 개발자의 책장
- 프로그래머스
- 자바스크립트
- 정규표현식
- 재귀함수
- 코딩공부
- 블록체인
- 알고리즘
- array.push()
- Developer_JoyKim
- array.slice()
- 코딩테스트
- SQL
- MySQL
- 코드스테이츠
- select
- node.js
- Hackerrank
- JavaScript
- Algorithms
- 코플릿
- Where
- array
- Programmers
- 개발자_조이킴
- join
- for문
- 배열
Archives
- Today
- Total
CodingSpace
[HackerRank/SQL] Advanced Select - Binary Tree Nodes 본문
Problem. Advanced Select - Binary Tree Nodes
Link.
https://www.hackerrank.com/challenges/binary-search-tree-1/problem?isFullScreen=true
Binary Tree Nodes | HackerRank
Write a query to find the node type of BST ordered by the value of the node.
www.hackerrank.com
Description.
You are given a table, BST, containing two columns: N and P, where N represents the value of a node in Binary Tree, and P is the parent of N.
Write a query to find the node type of Binary Tree ordered by the value of the node.
Output one of the following for each node:
- Root: If node is root node
- Leaf: If node is leaf node
- Inner: If node is neither root nor leaf node
Key Point.
CASE WHEN,
IS,
IN,
CONCAT,
ORDER BY,
DISTINCT,
My Answer.
SELECT
CASE
WHEN P IS NULL THEN CONCAT(N, ' Root')
WHEN N IN (SELECT DISTINCT SB.P FROM BST SB) THEN CONCAT(N, ' Inner')
ELSE CONCAT(N, ' Leaf')
END
FROM BST
ORDER BY N ASC;
References.
'HackerRank > SQL' 카테고리의 다른 글
[HackerRank/SQL] Aggregation - Weather Observation Station 14 (0) | 2022.08.01 |
---|---|
[HackerRank/SQL] Aggregation - Weather Observation Station 13 (0) | 2022.07.31 |
[HackerRank/SQL] Alternative Queries - Draw The Triangle 2 (0) | 2022.07.22 |
[HackerRank/SQL] Basic Select - Weather Observation Station 12 (0) | 2022.07.20 |
[HackerRank/SQL] Aggregation - Japan Population (0) | 2022.07.19 |
Comments