SQLite3 select field by numeric range

人盡茶涼 提交于 2019-12-11 06:49:39

问题


in SQLite3, say i have this simple table

rowid     value1    value2
(int)     (float)   (float)  
1         15.3      20.2
2         17.8      30.5
3         15.8      25.3
4         16.1      48.0

How could I select those rows where the values are:
15.0 >= value1 <= 16.5 - effectively selecting rows 1,2 & 3

further how can i refine adding to the first criteria this to ALSO 20.0 >= value2 <= 37.0 - selecting then only row 1 & 3?

Your help is highly appreciated


回答1:


I believe your first logic is not correct, for if value1 is less than 15, it will also be less than 16.5, but just change the operators:

Select * from SimpleTable where value1 <= 15.0 and value1 <= 16.5;

Maybe you meant:

Select * from SimpleTable where value1 >= 15.0 and value1 <= 16.5;

Again (considering the adjusted logic):

Select * from SimpleTable where value1 >= 15.0 and value1 <= 16.5 and value2 >= 20.0 and value2 <= 37.0;

You might want to add and "order by" clause if you want your results sorted.




回答2:


Simply execute the SQL command below :

select id, value1, value2 FROM <table name> WHERE value1 >= 15.0 AND  value1 <= 16.5 AND value2 >= 20.0 AND value2 <= 37.0


来源:https://stackoverflow.com/questions/8313777/sqlite3-select-field-by-numeric-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!