使用 SQL 'With' 子句时出错 [英] Error using SQL 'With' clause

查看:20
本文介绍了使用 SQL 'With' 子句时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在使用的查询.此查询出现错误.'WITH' 子句附近的语法错误.

This is the query that I am using. I am getting an error with this query. 'syntax error near 'WITH' clause.

WITH RECURSIVE under_cust (affiliation_id, from_customer_id, to_customer_id, to_name,     parent_customer_type, child_customer_type, level) 
 AS (SELECT af.affiliation_id, 
       from_customer_id, 
       to_customer_id, 
       to_name, 
       parent_customer_type, 
       child_customer_type, 
       0 LEVEL 
     FROM   affiliation af, 
                customer c 
         WHERE  to_customer_id <> from_customer_id 
                AND af.from_customer_id = c.customer_id 
                AND af.to_customer_id = 1000022559337 
         UNION ALL 
         SELECT af.affiliation_id, 
                af.from_customer_id, 
                af.to_customer_id, 
                af.to_name, 
                af.parent_customer_type, 
                af.child_customer_type, 
                under_cust.level + 1 LEVEL 
         FROM   customer c, 
                affiliation af 
                JOIN under_cust smr 
                  ON smr.from_customer_id = af.to_customer_id 
         WHERE  af.from_customer_id = c.customer_id 
) SELECT affiliation_id, 
   to_customer_id   parent, 
   from_customer_id child, 
   to_name, 
   parent_customer_type, 
   child_customer_type, 
   level 
FROM   under_cust 

推荐答案

常用表表达式和 WITH 语法最近才在 sqlite 3.8.3 版.

Common table expressions and the WITH syntax were introduced only recently in sqlite version 3.8.3.

如果您在旧版本上运行查询,则会出现语法错误.

If you run the query on an older version, you get the syntax error.

升级您的 sqlite 或让您的代码在没有 WITH 语法的情况下工作.

Either upgrade your sqlite or make your code work without the WITH syntax.

这篇关于使用 SQL 'With' 子句时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆