如何对varchar列进行排序? [英] How to sort varchar column ?
本文介绍了如何对varchar列进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的表:
I have a table like this:
col1 col2
1 1
2 1a
3 2
4 10
5 a-1
6 a-2
并且col2的类型是varchar,当我默认执行order by
col2时,结果如下:
and the type of col2 is varchar, when I do order by
col2 default,the result like this:
col2
1
10
1a
2
a-1
a-2
但我想要这样:
but I want it like this:
col2
1
1a
2
10
a-1
a-2
我不想使用用户定义的函数来执行此操作.
I don''t want to do it using user-defined function.
help me!
推荐答案
您想要的是自然的选择.
我知道的任何数据库都不支持它.
原因是大多数数据库索引使用B树索引,其中B代表二进制.排序使用索引.
因此,自然排序将需要全表扫描,这在许多情况下会严重影响性能.
此处 [
What you want is a natural sort.
It isn''t supported by any db that I''m aware of.
The reason for this is that most indexing of databases uses B-Tree index where B stands for Binary. Sorting uses the index.
So natural sorting would need a full table scan which in many cases would be a serious performance hit.
Here[^] is an article on how to implement natural sorting using C#.
这篇关于如何对varchar列进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文