SQL Server Orderby()错误 [英] Sql Server Orderby() error

查看:123
本文介绍了SQL Server Orderby()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只包含1到121个数字的表.

我想按编号订购

例子

我有一个名为 tbl_numbers 的表,其中只有一个字段 number
提交的号码连续包含1到121个号码

我想把它显示为
1
2
3
4
5
6
7
8等

我用这个查询

从tbl_numbers中按数字顺序选择数字


像这样

1
10
11
12
13
2
3
4
5
6
7
8
9等

那是唯一的第一个数字..



有人可以帮我解决这个问题吗?

会很棒的

Kishore R

i have a table containing 1 to 121 numbers only.

i want to order it by number

Example

i have a table named tbl_numbers having only one field number
the filed number contains 1 to 121 numbers consecutively

i want to show it like
1
2
3
4
5
6
7
8 etc

i used this query

select number from tbl_numbers order by number


its showing like this

1
10
11
12
13
2
3
4
5
6
7
8
9 etc

that is it is jus ttaking the first digit only..



can anyone help me to solve this?

it will be a great one

Kishore R

推荐答案

这是因为sql中的number列数据类型是VARCHAR r.它应该是INT.然后只有排序才能起作用.
It because your number column datatype in sql is VARCHAR r any other. It should be INT. Then only sorting will work.


请尝试以下操作:
Try this:
SELECT number FROM tbl_numbers ORDER BY number+0


您的解决方案在这里:

Your Solution Here:

SELECT Number FROM tbl_Numbers ORDER BY Convert(INT,Number)


这篇关于SQL Server Orderby()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆