简体   繁体   中英

How to query in SQLite using BETWEEN and DOUBLE values?

Hi everyone I have to query from db using BETWEEN on two DOUBLE values

This is my Table:

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" + ");");

I want to show all nearest Tasks and my current QUERY is:

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

I dont know is it wrong or not, i have found it somewhere in this forum. This query returns me nothing... How it shoud be done?

a BETWEEN b AND c is the same as a >= b AND a <= c .

So you have to ensure that the smaller of the two values comes before the AND .

Just change the order of the top and bottom in your query:

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

Your sample filled query would be like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM