基于字母数字在sql server中对数据进行排序 [英] sorting of data in sql server on the basis of Alphanumeric

查看:99
本文介绍了基于字母数字在sql server中对数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.这是表结构

EmployeeID EmployeeName等级
1迪帕克第一
2考沙尔秒
3 Pankaj First
4拉胡尔第三名
5利雅兹第四
6个邪恶的五人
6 Suresh第四名


我想按升序显示它,如下所示:


EmployeeID EmployeeNAme排名
1迪帕克第一
3 Pankaj First
2考沙尔秒
4拉胡尔第三名
5利雅兹第四
6 Suresh第四名
6个邪恶的五人

是否可以使用sql server?

1. Here is the table structure

EmployeeID EmployeeName Rank
1 Deepak First
2 Kaushal Second
3 Pankaj First
4 Rahul Third
5 Riyaz Fourth
6 vimal Five
6 Suresh Fourth


I want to display it in ascending order as shown below :


EmployeeID EmployeeNAme Rank
1 Deepak First
3 Pankaj First
2 Kaushal Second
4 Rahul Third
5 Riyaz Fourth
6 Suresh Fourth
6 vimal Five

Is it possible to using sql server ?

推荐答案

否,直接解决此问题的方法.

两种可能的解决方案如下,
1. 创建代表相似单词数的新表
no, direct way to solve this.

two possible solutions are as below,
1. create new table that represent similar number of word
Rank   number
First  1
second 2
.
.
.


现在,使用等级列&将表格与上面的表格连接起来然后按数字"列进行排序

2. 创建将单词转换为数字的函数.
您将获得相似单词的编号,然后按该编号值进行排序

祝您编码愉快!
:)


Now, join your table with above table using rank column & then order by ''Number'' column

2. create function that converts word to number.
you will get number of similar word and then order by that number value

Happy Coding!
:)


我建​​议考虑使用例如Aarti建议的查找表,但不要使用单词作为连接列,而是使用查找表的键.因此,两个表都将等级定义为数字,而查找表将包含等级说明.

但是,如果使用表中的等级来定义某些条件的行顺序,则将其完全删除.我建议这样做是因为,如果重行是行的顺序,则每次插入,删除或更新记录或条件更改时,都需要重新计算排名.如果情况是这样,通常会在运行查询时生成该排名,而根本不会存储该排名.
I would suggest considering using for example a lookup table as Aarti suggested, but not to use the word as a joining column but the key of the lookup table. So both tables would have rank defined as a number and the lookup table would contain the description for the rank.

However, if the rank in your table is used to define the order of the rows for certain criteria, I would remove it completely. I''m suggesting this because if the reank is the order of the rows, you need to recalculate the ranks every time you insert, delete or update the records or the criteria changes. If the situation is like that, the rank is typically generated when a query is ran and it''s not stored at all.


这篇关于基于字母数字在sql server中对数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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