Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
811 views
in Technique[技术] by (71.8m points)

sqlite - Error using SQL 'With' clause

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 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...