小编典典

将查询从MySql转换为Sqlite

sql

我需要将此查询从MySQL格式转换为SQLite。我正在尝试自己,但发现了一些困难。

在SQLite中,curdate()和interval函数不存在。

select a.Date 
from (
    select curdate() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as Date
    from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a
    cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b
    cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c
) a
where a.Date between '2010-01-20' and '2010-01-24'

阅读 150

收藏
2021-04-14

共1个答案

小编典典

这是基本语法:

select a.Date 
from (select date('now', '-'||(a.a + (10 * b.a) + (100 * c.a))|| ' days') as Date
      from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9
           ) a cross join
           (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9
           ) b cross join
           (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9
           ) c
    ) a;

我忽略了该where子句,因为这些日期是过去1000多个日期,因此他们无论如何都不会选择任何内容。

2021-04-14