SQL排序按 名称排序字母汉字混排

我现有一字段值为
name
------------------------
BBB
CCC
阿阿
查查
AAA
拔拔
怎么样排序可以实现
name
--------------
AAA
阿阿
BBB
拔拔
CCC
查查

--首先准备一个拼音表
CREATE TABLE AWord(
PY varchar(10),
ZW nvarchar(10)
) ON [PRIMARY]
GO
--插入数据
insert into aword
select 'A',N'骜'
union all select 'B',N'簿'
union all select 'C',N'错'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鳆'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'沤'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'箨'
union all select 'W',N'鹜'
union all select 'X',N'鑂'
union all select 'Y',N'韵'
union all select 'Z',N'咗'
GO
--建立一个获取拼音首字母的函数
create function f_GetPY
(
@str nvarchar(2)
)
returns nvarchar(2)
as
begin
set @str = left(@str, 1)
return (
case when unicode(@str) between 19968 and 19968+20901 then(
select top 1 PY+'.' from aword where zw>=@str
collate Chinese_PRC_CS_AS_KS_WS order by PY ASC
) else @str end
)
end
GO
--然后查询排序
select * from 表 order by dbo.f_GetPY(字段)
温馨提示:内容为网友见解,仅供参考
无其他回答

SQL,排序问题,请高手指教
ORDER BY SUBSTR(field, 1, length(field))

通过vb如何实现按中文词语拼音的首字母排序?
'在窗口中加两个TEXT控件,一个输入中文,一个显示英文 Private Sub Form_Load()Text1.Text = "转汉语拼音"End Sub Private Sub Command1_Click()Text2.Text = GetPY(Text1.Text)End Sub '获得输入名称的首字拼音 Private Function GetPY(ByVal strParmeter As String) As String Dim intTmp ...

SQL语句中UNION排序问题
select a.输出字段1, a.输出字段2, a.输出字段3, ...a.输出字段n from (select * ,1 as px from 表A where 软件名称 like '%迅雷%'union select * ,2 from 表A where 软件简介 like '%迅雷%') a order by a.px 如果不在意多出一个用于排序的字段“px”的话,代码可简化如下 sel...

相似回答