在sql中的排序问题

wuzhanxi 2003-12-02 08:42:08
例如:有(03,15,16,08,10)如何经过排序后得到如下顺序
(03,08,10,15,16)
...全文
15 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzh1215 2003-12-02
  • 打赏
  • 举报
回复
缺了点

直接用:
order by 字段
就行了。
如果是('3','15','16','8','10')
就得用:order by cast(字段 as int)
wzh1215 2003-12-02
  • 打赏
  • 举报
回复
直接用:
order by 字段
就行了。
如果是('3','15','16','8','10')
就得用:order by cast(字段 as in)
realgz 2003-12-02
  • 打赏
  • 举报
回复
declare @x table (t varchar(200))
declare @x2 varchar(200)
set @x2='03,15,16,08,10'
set @x2=@x2+','
while @x2<>''
begin
insert into @x (t) values (left(@x2,charindex(',',@x2)-1))
set @x2=right(@x2,len(@x2)-charindex(',',@x2))
end
select @x2=@x2+t+',' from @x order by t
set @x2=left(@x2,len(@x2)-1)
print @x2
pengdali 2003-12-02
  • 打赏
  • 举报
回复
order by 字段+0
victorycyz 2003-12-02
  • 打赏
  • 举报
回复
order by 字段 --这样难道不能正确排序吗?
txlicenhe 2003-12-02
  • 打赏
  • 举报
回复
order by cast(字段 as int)

22,209

社区成员

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

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