一个简单sql问题

huyidehyd 2003-11-07 04:17:57
一字段为字符型a,其中一值为"abc",我想取小于和大于该值的各5个值(最接近),如何取?
...全文
24 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
huyidehyd 2003-11-07
  • 打赏
  • 举报
回复
谢谢,结贴!
wzh1215 2003-11-07
  • 打赏
  • 举报
回复
select top 5 from table1 where a<'abc' order by a desc
union all
select top 5 from table1 where a>'abc' order by a
pengdali 2003-11-07
  • 打赏
  • 举报
回复
select top 5 * from xx where a<>'abc' order by abs(cast(a as varbinary)-cast(cast('abc' as varbinary) as int))
txlicenhe 2003-11-07
  • 打赏
  • 举报
回复
Select top 5 * from 表 where 字段<'abc' order by 字段 desc

Select top 5 * from 表 where 字段>'abc'

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧