WITH RECURSIVE category_tree AS ( SELECT id, name, parent_id, 0 AS level FROM categories WHERE parent_id IS NULL UNION ALL SELECT c.id, c.name, c.parent_id, ct.level + 1 FROM categories c JOIN category_tree ct ON c.parent_id = ct.id)SELECT * FROM category_tree; RECURSIVE报错语法错误
时间: 2024-02-16 21:05:08 浏览: 127
freertos.rar_2440 FREERTOS_freertos_recursive semaphore_嵌入式
根据您提供的代码片段,出现语法错误的可能原因是在使用WITH RECURSIVE时,前面的查询子句中没有使用逗号分隔不同的SELECT语句,导致解析出错。您可以尝试将两个SELECT语句用逗号分隔开来,如下所示:
```
WITH RECURSIVE category_tree AS (
SELECT id, name, parent_id, 0 AS level
FROM categories
WHERE parent_id IS NULL
UNION ALL
SELECT c.id, c.name, c.parent_id, ct.level + 1
FROM categories c
JOIN category_tree ct ON c.parent_id = ct.id
)
SELECT * FROM category_tree;
```
这应该可以解决语法错误问题。如果还有其他问题,请提供具体的错误信息,以便我更准确地帮助您解决问题。
阅读全文