Thu*_*der 49 sql database sqlite date
我有一个带有出生日期的sqlite表.我想执行一个查询来选择那些年龄超过30岁的记录.我尝试过以下但是它不起作用:
select * from mytable where dob > '1/Jan/1980'
select * from mytable where dob > '1980-01-01'
Run Code Online (Sandbox Code Playgroud)
Thu*_*der 72
可以使用这样的东西:
select dateofbirth from customer Where DateofBirth BETWEEN date('1004-01-01') AND date('1980-12-31');
select dateofbirth from customer where date(dateofbirth)>date('1980-12-01');
select * from customer where date(dateofbirth) < date('now','-30 years');
Run Code Online (Sandbox Code Playgroud)
如果您使用的是Sqlite V3.7.12或更高版本
不要date(dateofbirth)
只使用dateofbirth
.所以你的查询看起来像这样:
select * from customer where dateofbirth < date('now','-30 years');
Run Code Online (Sandbox Code Playgroud)
My *_* Me 21
在sqlite网站上使用魔术文档:
select * from mytable where dob < date('now','-30 years');
Run Code Online (Sandbox Code Playgroud)
尝试使用日期格式“YYYY-MM-DD”
select * from mytable where dob > '1980-01-01'
Run Code Online (Sandbox Code Playgroud)
更程序化的方式是这样的:
select * from mytable where datediff(dob, now()) > 30
Run Code Online (Sandbox Code Playgroud)
您需要为 sqlite 找到特定的语法。
归档时间: |
|
查看次数: |
79413 次 |
最近记录: |