在sqlite中使用create table< name>作为select创建表时出错

qnzebej0  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(455)

我试图创建一个日期表,为特定的日期范围生成eom日期,但是sqlite在创建表时抛出了一个错误。我目前的代码如下:

WITH RECURSIVE cnt (
        x
) AS (
    SELECT
            0
    UNION ALL
    SELECT
            x + 1
    FROM
            cnt
    LIMIT (
            SELECT
                    ROUND(((julianday ('2020-05-01') - julianday ('2016-04-01')) / 30) + 1))
)

CREATE TABLE report_dates AS
SELECT
  date(date(julianday ('2016-04-01'), '+' || x || ' month'), '-1 day') AS month
FROM
  cnt;

然而,我得到了错误 Query 1 ERROR: near "CREATE": syntax error . 卸下 CREATE TABLE report_dates AS 线条确实可以显示结果。是什么驱动了这一切?

iswrvxsc

iswrvxsc1#

cte追求 create table :

CREATE TABLE report_dates AS
WITH RECURSIVE cnt (x) AS (
    SELECT 0
    UNION ALL
    SELECT x + 1
    FROM cnt
    LIMIT (
        SELECT ROUND(((julianday ('2020-05-01') - julianday ('2016-04-01')) / 30) + 1)
    )
)
SELECT date(date(julianday ('2016-04-01'), '+' || x || ' month'), '-1 day') AS month
FROM cnt;

相关问题