当前位置:
代码迷
>>
Sql Server
>> 有没有简略的sql语句查差别最小的记录
详细解决方案
有没有简略的sql语句查差别最小的记录
热度:
20
发布时间:
2016-04-24 23:17:55.0
有没有简单的sql语句查差别最小的记录
比如表有个字段是数值型的,各类数字都有。我现在想查出跟5最接近的那条记录
------解决方案--------------------
select top 1 col1 from tb order by abs(5-col1)
------解决方案--------------------
select min(col) from tb where col>5
select max(col) from tb where col<5
查看全文
相关解决方案