在db2中选择10大于10且小于10的整数值。

时间:2014-08-23 10:46:42

标签: sql database select db2 union

我想编写一个select语句,它将返回10行,其列值大于输入整数,10行的列值小于输入整数。

2 个答案:

答案 0 :(得分:2)

SELECT * FROM [table] WHERE Column > 100 FETCH FIRST 10 ROWS ONLY
UNION ALL
SELECT * FROM [table] WHERE Column < 100 FETCH FIRST 10 ROWS ONLY

答案 1 :(得分:0)

如果你愿意,这是另一种解决方案:

select t.*
from (select t.*,
             row_number() over (partition by (case when col < target_val then 'lower' else 'higher' end),
                                order by abs(target_val - col)
                               ) as seqnum
      from table t
     ) t
where seqnum <= 10;