我想编写一个select语句,它将返回10行,其列值大于输入整数,10行的列值小于输入整数。
答案 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;