SQL按汉语拼音首字母排序

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

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
SQL按汉语拼音首字母排序

其运行结果如下图:

SQL按汉语拼音首字母排序

SQL按汉语拼音首字母排序,布布扣,bubuko.com

SQL按汉语拼音首字母排序

上一篇:远程数据库备份到本地或转移到其他位置


下一篇:[Acwing237] 程序自动分析