> For the complete documentation index, see [llms.txt](https://851958789.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://851958789.gitbook.io/notes/0608_tree_node/slt.md).

# 思路1 left join + case when

```sql
SELECT t1.id,
CASE
  WHEN t1.p_id IS NULL THEN "Root"
  WHEN t2.p_id IS NULL THEN "Leaf"
  ELSE "Inner"
END AS Type
FROM tree t1 LEFT JOIN tree t2
ON t1.id=t2.p_id
GROUP BY t1.id;
```
