日期:2014-05-17  浏览次数:20384 次

关于排序的小问题,谁有好方法呀
排序问题。如:
红色
紫红色
灰色
棕红色
深灰色
浅灰色
绿色
青灰色
血红色
……

如何按后面的字排序,就是红色在一起,灰色的在一起(就是字从后往前排)


------解决方案--------------------
正则?
------解决方案--------------------
探讨

引用:
正则?

详细说说呀

------解决方案--------------------
可以写一个sql函数将汉字转换为拼音。然后排序就容易了
------解决方案--------------------
把字符串Reverse倒序再排
------解决方案--------------------
探讨
把字符串Reverse倒序再排

------解决方案--------------------

我想了许久,终于想到了方法了,
 
先是建个表 --T_Color
id Fcolor
1 红色
2 紫红色
3 灰色
4 棕红色
5 深灰色
6 浅灰色
7 绿色
8 青灰色
9 血红色
10 浅红色
SQL code

select tab.id,tab.Fcolor from
(
    select id as 'id'
            ,(case 
                when len(Fcolor)=2 then ('_'+Fcolor)
                when len(Fcolor)>2 then (Fcolor)
                else '无'
                end
            )as 'Fselect' --我就是补这个字段来排序的
            ,Fcolor as 'Fcolor'
    from T_Color
) as tab 
order by substring(tab.Fselect,2,1)

------解决方案--------------------
不知有更简单的
如果楼主找到了,
还望贴出来参考下!
------解决方案--------------------
定义个比较的方法,然后用list的排序功能。
------解决方案--------------------
汉字转拼音,然后按字母排序
[code=C#]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace TS.Capture.Helpers
{
public class Han2PinHelper
{
#region 把汉字转化成全拼音
private static int[] pyValue = new int[]
{
-20319,-20317,-20304,-20295,-20292,-20283,-20265,-20257,-20242,-20230,-20051,-20036,
-20032,-20026,-20002,-19990,-19986,-19982,-19976,-19805,-19784,-19775,-19774,-19763,
-19756,-19751,-19746,-19741,-19739,-19728,-19725,-19715,-19540,-19531,-19525,-19515,
-19500,-19484,-19479,-19467,-19289,-19288,-19281,-19275,-19270,-19263,-19261,-19249,
-19243,-19242,-19238,-19235,-19227,-19224,-19218,-19212,-19038,-19023,-19018,-19006,
-19003,-18996,-18977,-18961,-18952,-18783,-18774,-18773,-18763,-18756,-18741,-18735,
-18731,-18722,-18710,-18697,-18696,-18526,-18518,-18501,-18490,-18478,-18463,-18448,
-18447,-18446,-18239,-18237,-18231,-18220,-18211,-18201,-18184,-18183, -18181,-18012,
-17997,-17988,-17970,-17964,-17961,-17950,-17947,-17931,-17928,-17922,-17759,-17752,
-17733,-17730,-17721,-17703,-17701,-17697,-17692,-17683,-17676,-17496,-17487,-17482,
-17468,-17454,-17433,-17427,-17417,-17202,-17185,-16983,-16970,-16942,-16915,-16733,
-16708,-16706,-16689,-16664,-16657,-16647,-16474,-16470,-16465,-16459,-16452,-16448,
-16433,-16429,-16427,-16423,-16419,-16412,-16407,-16403,-16401,-16393,-16220,-16216,
-16212,-16205,-16202,-16187,-16180,-16171,-16169,-16158,-16155,-15959,-15958,-15944,
-15933,-15920,-15915,-15903,-15889,-15878,-15707,-15701,-15681,-15667,-15661,-15659,
-15652,-15640,-15631,-15625,-15454,-15448,-15436,-15435,-15419,-15416,-15408,-15394,
-15385,-15377,-15375,-15369,-15363,-15362,-15183,-15180,-15165,-15158,-15153,-15150,