从表中获取行的问题 [英] problem in fetching rows from table

查看:50
本文介绍了从表中获取行的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们。



我有一张桌子,上面有超过20行。我有一个查询从该表中获取具有相同列的20行。这20行有一列,每行有一个从1到20的值。例如,第一行的列'radif'表示其值为6,第二行的radif列的值为13,其他行如此。我想选择一个最大值为radif列的行。我不知道radif的最大数量,也不知道它的放置位置。我测试了这个我的自己20行并且用'命令由radif asc'命令ssms按此顺序返回数字

1-10-11-12-13-14-15-16-17- 18-19-2-3-4-5-6-7-8-9.i想以这种格式返回ssms返回radif - >

1-2-3-4-5 -6 -...

我该怎么办?请帮帮我。

提前谢谢。

hi friends.

i have a table that i have more than 20 rows on it. i have a query for fetching 20 rows from this table that have a same column. and this 20 rows have a column that for every row it has a value from 1 to 20. for example first row has column 'radif' that its value is 6, second rows radif column has value of 13 and others like this. i want to select a row that has a maximum value of radif column. i do not know maximum number of radif and do not know where it is placed. i tested this my self for 20 rows and with a 'order by radif asc' command ssms return numbers in this order
1-10-11-12-13-14-15-16-17-18-19-2-3-4-5-6-7-8-9.i want to ssms return radif in this format-->
1-2-3-4-5-6-...
how can i do that?please help me.
thanks in advance.

推荐答案

麻烦的是你已经将你的数字存储为一个字符串 - 所以它使用strign比较一切,并且逐个字符地工作。不同的第一个字符决定比较。



最好的解决方案是永远不要将数字数据存储为字符串;使用数字字段。这样比较工作正常,你可以使用数学操作等有用的东西。



如果不这样做,你需要将strign转换为数字 - 并且希望比如说它们都不包含坏字符......

The trouble is that you have stored your numer as a string - so it uses a strign comparision for everything, and that works on a character-by-character basis. The firts character that is differnet decides the comparison.

The best solution is never to store numeric data as strings; use a numeric field. That way comparisons work properly, and you can useful things like math operations on them.

Failing that, you'd need to convert the strign to an number - and hope like heck that none of them contain "bad" characters...
...ORDER BY CAST(radif AS INT) ASC

会暂时做,但要认真 - 改变你的数据库!

Will do it temporarily, but seriously - change your DB!


这篇关于从表中获取行的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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