mariadb With子句,递归查询语法错误

uqcuzwp8  于 2022-12-18  发布在  其他
关注(0)|答案(1)|浏览(110)

运行此查询时,我收到错误:SQL语法中有错误;查看与您的MariaDB服务器版本对应的手册,了解在第7行的'WITH works as(SELECT ath.dblpkey from(authors as ath)where author in(sele...'附近使用的正确语法

WITH RECURSIVE
authors as ((select dblpkey, author from inproau) union all (select dblpkey, author from artiau))
,collegues(collegue) as 
(
    SELECT "Paul Erdös" #as collegue
        UNION ALL
    (WITH works as (SELECT ath.dblpkey from (authors as ath) where author in (select collegue from collegues))
        (SELECT DISTINCT author from authors where dblpkey in (select dblpkey from works)))
) 
select * from collegues

我试着查找SQL的语法规则,但仍然没有找到我违反的语法规则

ax6ht2ek

ax6ht2ek1#

正如评论员已经说过的,你不能嵌套CTE,所以工程必须上升
你也许可以把它简化一点,但是没有数据,这是不可能的

WITH RECURSIVE
authors as (
            (select dblpkey, author from inproau) 
            union all 
            (select dblpkey, author from artiau))
,works as (SELECT ath.dblpkey from (authors as ath) where author in (select collegue from collegues)) 
,
collegues(collegue) as 
(
    SELECT "Paul Erdös" #as collegue
        UNION ALL    
        (SELECT DISTINCT author from authors where dblpkey in (select dblpkey from works))
) 
select * from collegues

相关问题