zoukankan      html  css  js  c++  java
  • SQL按汉语拼音首字母排序

    以常用到的省的数据表(province)为例,其中name字段为省的名称,SQL语句如下:

     1 select   isnull(b.py,upper(left(a.name,1)))     as   py  
     2   ,a.name  
     3   from   province
     4   a  
     5   left   outer   join   (  
     6   select   'A'   as   PY,N''   as   word,   N''   as   sword  
     7   union   select   'B',N'簿',N''  
     8   union   select   'C',N'',N'簿'  
     9   union   select   'D',N'',N''  
    10   union   select   'E',N'',N''  
    11   union   select   'F',N'',N''  
    12   union   select   'G',N'',N''  
    13   union   select   'H',N'',N''  
    14   union   select   'J',N'',N''  
    15   union   select   'K',N'',N''  
    16   union   select   'L',N'',N''  
    17   union   select   'M',N'',N''  
    18   union   select   'N',N'',N''  
    19   union   select   'O',N'',N''  
    20   union   select   'P',N'',N''  
    21   union   select   'Q',N'',N''  
    22   union   select   'R',N'',N''  
    23   union   select   'S',N'',N''  
    24   union   select   'T',N'',N''  
    25   union   select   'W',N'',N''  
    26   union   select   'X',N'',N''  
    27   union   select   'Y',N'',N''  
    28   union   select   'Z',N'',N''  
    29   )   b   on   left(name,1)   between   b.sword   and   b.word order by name

    其运行结果如下图:

  • 相关阅读:
    java内部类
    unityUI拖拽
    Java泛型
    java集合
    python爬取糗百段子
    python读取文件并保存到mysql数据库
    BeanShell Sampler 身份证号-jmeter
    python操作数据库
    创建身份证号
    随机生成四要素
  • 原文地址:https://www.cnblogs.com/Chaser-Eagle/p/3684815.html
Copyright © 2011-2022 走看看