查询最接近某一数值的sql 查询某一列中最小的数

来源:互联网 发布:tcp网络编程 客户端 编辑:程序博客网 时间:2024/06/05 03:16

create table #temp

(

    id int,

    分数 decimal(10, 1)

)

insert #temp

select 1,35 union all

select 2,0 union all

select 3,75 union all

select 4,0 union all

select 5,37 union all

select 6,74 union all

select 7,45 union all

select 8,0 union all

select 9,34.5

go

 

select * from #temp

 

select top(1) * from #temp order by abs(分数-34)

 

select  * from #temp where 分数=(select MIN(分数) from #temp)

 

select top(1) with ties * from #temp order by 分数

原创粉丝点击