sql - 使用 CREATE TABLE 在 SQLite 中创建表时出错作为选择
问题描述
我正在尝试创建一个为特定日期范围生成 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
线确实使结果没有问题。是什么驱动了这一切?
解决方案
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;
推荐阅读
- spring - 使用 Spring AOP 无法在 Web 应用程序中进行日志记录
- laravel - 如何在 Laravel Auth 登录检查中更改为 bcrypt 而不是 md5
- python - Jupyter:[Errno -2]名称或服务未知错误
- php - 使用 SimpleXMLElement 访问 RSS 提要中的项目
- php - 删除列中的重复数据
- c# - 使用 C# 中的计时器运行每 X 秒的方法 24 小时
- python - 如何在 django rest 框架中使用外键计数
- react-native - 找不到 ReactNativeComponentTree 文件
- c# - 在下面的代码中,我想为 GridViewBind() 添加 if 语句,在 else 情况下,我想说“没有要显示的数据”
- safari - ApplePay JS 在 onpaymentauthorized 之前失败