我想知道sqlite3是否支持间隔功能。 PostgreSQL接受以下语句,但是sqlite3无法解析它;
select
...
from
orders
where
...
and o_orderdate < date '1995-03-01' + interval '3' month
错误:靠近第4行:靠近“'1995-03-01'”:语法错误
然后,我修改了一些语句,如;
and o_orderdate < date('1995-03-01') + interval '3' month
这次错误是; 错误:靠近第4行:靠近“'3'”:语法错误
不幸的是,同样的技巧对区间函数不起作用,即
and o_orderdate < date('1995-03-01') + interval('3' month)
或
and o_orderdate < date('1995-03-01') + interval('3') month
甚至
and o_orderdate < date('1995-03-01') + interval(3 month)
仍然给了我语法错误。
也许sqlite3不支持间隔功能或我在使用中遗漏了什么?
非常感谢
答案 0 :(得分:7)
and o_orderdate < date('1995-03-01', '+3 month')
答案 1 :(得分:0)
try this:
and date(o_orderdate) < date('1995-03-01','+3 month')
In order to calculate dates, you must inform to SQLite that your database field is a date: date(o_orderdate)
SQLite syntax is pretty unflexible, so it's important to make sure that the + sign has no spaces to the following number: '+3 month'