如何使用BETWEEN和DOUBLE值在SQLite中查询?

时间:2014-06-10 11:53:34

标签: android sqlite gps

大家好,我必须在两个DOUBLE值上使用BETWEEN从db查询

这是我的表:

db.execSQL("CREATE TABLE Task ("
                    + "id smallint(6) NOT NULL,"
                    + "project_id smallint(6) NOT NULL," 
                    + "add_date varchar(15) NOT NULL,"
                    + "geo_lat double NOT NULL,"
                    + "geo_long double NOT NULL,"
                    + "additional_info TEXT NULL" + ");");

我想显示所有最近的任务,我当前的QUERY是:

SELECT * FROM Task WHERE geo_lat BETWEEN " + lat_top + " AND " + lat_bot + " AND geo_long" + " BETWEEN " + long_top + " AND " + long_bot

我不知道是不是错了,我在这个论坛的某个地方找到了它。这个查询什么也没有给我什么......怎么回事?

2 个答案:

答案 0 :(得分:3)

a BETWEEN b AND ca >= b AND a <= c相同。

因此,您必须确保两个值中较小的值位于AND之前。

答案 1 :(得分:1)

只需更改查询中顶部和底部的顺序:

SELECT * FROM Task WHERE geo_lat 
     BETWEEN " + lat_bot+ " AND " + lat_top + " 
     AND geo_long" + " 
     BETWEEN " + long_bot + " AND " + long_top

您的示例填充查询将如下:

SELECT * FROM TASK WHERE 
( GEO_LAT BETWEEN 12.01 AND 12.50 ) 
AND
(GEO_LONG BETWEEN 81.10 AND 91.20)