首页 > 数据库技术 > 详细

SQL按汉语拼音首字母排序

时间:2014-04-25 05:13:37      阅读:743      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣
 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
bubuko.com,布布扣

其运行结果如下图:

bubuko.com,布布扣

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

SQL按汉语拼音首字母排序

原文:http://www.cnblogs.com/Chaser-Eagle/p/3684815.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!