比如有一个表tab1,数据为:
col1 col2 col3
10 abc def
20 hij dea
30 haha jiji
(col1不一定是整数可以是任意类型的数字,比如小数。)
给定一个值,16 可以得到10,和20两行
给定一个值,23 可以得到20,和30两行
如何用尽量少的语句查询??
---------------------------------------------------------------
select * from yourtable
where col1 between floor(val/10)*10 and ceil(val/10)*10
val 就是16或23
---------------------------------------------------------------
select max(col1) from tab where col1
1<val col1="" from="" min(col1)="" select="" tab="" union="" where="">val;
2\---------------------------------------------------------------
3
4利用分折函数,试一试吧,还没直正测试过.
5select * from table_name where col1 in (select col from (select col1,lead(col1,1,null) over(order by col1) next_col1 from table_name order by col1) where decode(sign(col1-值)+sign(next_col1-值),0,1)=0 and rownum<3)
6\---------------------------------------------------------------
7
8我有点误解了你的问题,那你还是用 more_zou(小人物) 的SQL吧,不过用union all效率高一点,因为两个集合不可能有重复项的。
9
10select max(col1) from tab where col1<val all="" col1="" from="" min(col1)="" select="" tab="" union="" where="">val;</val></val>