SQLite查询获取数据BETWEEN 2日期不起作用

时间:2011-12-08 20:34:55

标签: android database sqlite datetime

我在android中使用date sqlite,想要过滤两个日期之间的日期。我不知道我的查询到底有什么问题?它没有给出错误,但也没有给出结果。 我认为BETWEEN日期和日期函数

我做错了
SELECT * FROM trip_mark WHERE file_type = 2 
AND create_time BETWEEN date('2011-11-08 00:00:00') AND date('2011-11-10 00:00:00') 

下面是我的表格结构。我知道我的表中有日期,我正在使用SQLite浏览器并检查数据库中的数据。

CREATE TABLE `trip_mark` (
`file_id` INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL,
`local_path` varchar(100) DEFAULT NULL ,
`file_type` int(11) DEFAULT NULL,
`import_date` datetime DEFAULT NULL ,
`create_time` datetime DEFAULT NULL ,
`isSyncAvailable` int(11) DEFAULT '1' ,
`syncDate` datetime DEFAULT NULL ,
`isSynced` int(11) DEFAULT '0' ,
`longitude` float DEFAULT NULL ,
`altitude` float DEFAULT NULL ,
`place_logical_name` varchar(150) DEFAULT NULL ,
`file_note` varchar(250) DEFAULT NULL )

这是表当前数据

"1","/sdcard/TripMark_1323375027.jpg","2","2011-11-09 01:10:37","2011-11-09 01:10:37","1","null","0","-1","-1","Unknown Location","");
"2","/sdcard/TripMark_1323375053.jpg","2","2011-02-09 01:11:01","2011-02-09 01:11:01","1","null","0","-1","-1","Unknown Location","");
"3","/sdcard/TripMark_1323375260.jpg","2","2011-11-09 01:14:29","2011-11-09 01:14:29","1","null","0","-1","-1","Unknown Location","sdfas");

我想运行此查询

SELECT * FROM trip_mark WHERE file_type = 2 
AND create_time BETWEEN date('2011-11-08 00:00:00') AND date('2011-11-10 00:00:00') 

并且预期的输出数据是

"1","/sdcard/TripMark_1323375027.jpg","2","2011-11-09 01:10:37","2011-11-09 01:10:37","1","null","0","-1","-1","Unknown Location",""
"3","/sdcard/TripMark_1323375260.jpg","2","2011-11-09 01:14:29","2011-11-09 01:14:29","1","null","0","-1","-1","Unknown Location","sdfas"

4 个答案:

答案 0 :(得分:3)

SQLite没有datetimefloatintvarchar数据类型。请在此处查看可用类型列表:
http://www.sqlite.org/datatype3.html

答案 1 :(得分:2)

我遇到了同样的问题。我发现日期功能导致问题。由于''中的字符串已经是日期。我从查询中删除日期函数,它对我有用。您也可以尝试此查询。

SELECT * FROM trip_mark WHERE file_type = 2 
AND create_time BETWEEN '2011-11-08 00:00:00' AND '2011-11-10 00:00:00' 

答案 2 :(得分:0)

您查询的事实并未显示任何错误,这意味着它是正确的。确保您的数据库中有file_type = 2的记录。

编辑: 给出您的样本数据。您在file_type上存储字符串。删除file_type上的引号。

答案 3 :(得分:0)

SELECT * FROM transactionList 在什么时候交易日期' 2018-04-29' AND' 2018-05-29' 限制20;

尝试此查询,它将像哇:)

一样工作

请检查问题

Filter Not Working on date