SQL中英文混合排序



首先要创建一个存储过程



create function [dbo].[fn_ChineseToSpell](@strChinese varchar(500)='') 
returns varchar(500) 
as 
begin /*函数实现开始*/ 
    declare @strLen int,@return varchar(500),@i int 
    declare @n int,@c char(1),@chn nchar(1)  
    select @strLen=len(@strChinese),@return='',@i=0 
    while @i<@strLen 
    begin /*while循环开始*/
            select @i=@i+1,@n=63,@chn=substring(@strChinese,@i,1) 
            if @chn>'z'/*原理:“字符串排序以及ASCII码表”*/                
                select @n = @n +1,@c =case chn when @chn then char(@n) else @c end from(select top 27 * from (select chn = '吖' union all select '八' union all select '嚓' union all select '咑' union all select '妸'  union all select '发'  union all select '旮'  union all select '铪'  union all select '丌' /*because have no 'i'*/ union all select '丌' union all select '咔' union all select '垃' union all select '嘸' union all select '拏' union all select '噢' union all select '妑' union all select '七' union all select '呥' union all select '仨' union all select '他' union all select '屲' /*no 'u'*/ union all select '屲' /*no 'v'*/ union all select '屲' union all select '夕' union all select '丫' union all select '帀' union all select @chn) as a  order by chn COLLATE Chinese_PRC_CI_AS ) as b  
            else
                set @c=@chn
            set @return=@return+@c  
    end /*while循环结束*/  
    return(@return)  
end /*函数实现结束*/








然后就可以用了。substring 转换为英文首先字母



select substring(dbo.[fn_ChineseToSpell](name),1,1) as fw,* from member order by fw


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在HiveSQL中,有几个常用的排序函数,包括rank、dense_rank和row_number。这些函数可以用来对查询结果进行排序和生成序号。 rank函数是对查询结果进行排名,考虑over子句中排序字段值相同的情况。如果使用rank函数来生成序号,over子句中排序字段值相同的序号是一样的,后面字段值不相同的序号将跳过相同的排名号排下一个。rank函数的使用方法与row_number函数完全相同。例如,可以使用以下语句在HiveSQL中使用rank函数来生成序号: ``` SELECT RANK() OVER (ORDER BY column_name) AS rank, * FROM table_name; ``` dense_rank函数与rank函数类似,但在生成序号时是连续的。当出现相同排名时,dense_rank函数不会跳过相同排名号,而是紧接上一次的rank值。在各个分组内,rank()是跳跃排序,有两个第一名时接下来就是第四名,dense_rank()是连续排序,有两个第一名时仍然跟着第二名。可以使用以下语句在HiveSQL中使用dense_rank函数来生成序号: ``` SELECT DENSE_RANK() OVER (ORDER BY column_name) AS dense_rank, * FROM table_name; ``` row_number函数是最简单的排序函数,它为每一行生成一个唯一的序号,不考虑排序字段值相同的情况。可以使用以下语句在HiveSQL中使用row_number函数来生成序号: ``` SELECT ROW_NUMBER() OVER (ORDER BY column_name) AS row_number, * FROM table_name; ``` 以上是HiveSQL中常用的排序函数的用法。根据具体的需求,可以选择合适的函数来生成序号。 #### 引用[.reference_title] - *1* *2* [【数据库】HIVE SQL几种排序函数(ROW_NUMBER&RANK&DENSE_RANK)](https://blog.csdn.net/Jarry_cm/article/details/81904294)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [数据分析EPHS(11)-详解Hive中的排序函数](https://blog.csdn.net/abcdefg90876/article/details/105085553)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值