假如有以下表:(最小值是>=,最大值是<,这样的区间)
最小值 最大值 等级
0 1000 1
1000 2000 2
2000 3000 3
我现在有个已知数值1500,但我并不知道表中的数值区间是是什么样的,如何精准地取到对应等级的值?只需要2这一个值即可
select 等级 from 表 where 1500>=最小值列 and 1500<最大值列
oracle 查询日期区间内的数据一般最常用的就是between and 和>=,<=(或者不要等号)了;
举例:select * from tablename t where t.日期列 between to_date('2015-10-20 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')
或者:
select * from tablename where t.日期列 >= to_date('2015-10-20 00:00:00','yyyy-mm-dd hh24:mi:ss') and t.日期列 <= to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')
如果要查询开区间的数据只需将>= 和<=改为>和<就行。