【问题标题】:Error using SQL 'With' clause使用 SQL 'With' 子句时出错
【发布时间】:2014-06-04 19:55:43
【问题描述】:

这是我正在使用的查询。我收到此查询错误。 'WITH' 子句附近的语法错误。

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 

【问题讨论】:

  • 你有哪个版本的sqlite? 3.8.3 中添加了常用表表达式 - sqlite.org/changes.html
  • 文件扩展名为“.sqlite3”。如何找到版本?
  • 你是如何运行查询的?如果它是 sqlite3 shell,那么你可以找到版本,例如sqlite3 --version
  • 或者执行SELECT sqlite_version();
  • 好的,谢谢。它是旧版本(3.7.17)。需要考虑一个不使用'with'子句的替代方案..

标签: sqlite


【解决方案1】:

公用表表达式和WITH 语法最近才在sqlite version 3.8.3 中引入。

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

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

【讨论】:

    猜你喜欢
    • 2022-01-03
    • 1970-01-01
    • 2021-10-19
    • 2019-04-06
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 2013-03-12
    相关资源
    最近更新 更多