当前位置:网站首页>mysql按照首字母排序
mysql按照首字母排序
2022-07-06 06:19:00 【不允许摆烂】
今天测试提了个需求,按照字段的首字母进行排序
由于一般数据库编码大都为utf-8 ,他的排序方式为按英文字母规则排序 "a,b,c… "

由上表看出,只要我们在排序时将需要排序的字段转化为GBK编码再进行排序,就可以实现按照字段首字母进行排序了, 怎样才能将编码转化为GBK呢?在MySQL中提供了函数CONVERT() ,该函数可用来获取一个类型的值
该函数的使用方式为 CONVERT(字段 USING GBK)
例如:
SELECT * FROM table ORDER BY CONVERT(field USING GBK) ASC
下面是我sql例子 ,我的需求是按照单位的首字母排序
没有排序前
select
ier.id,
eor.id cid,
eor.sort,
ier.title,
ier.summary,
ier.expert_desc,
ier.proposal,
eor.status,
ier.tenant_id,
eor.level_one_code,
eor.cycle_id,
eor.monitor_organ_id,
eor.project_id,
so.name monitorOrganName
from
index_expert_reviews ier
left join
expert_organ_relation eor
on eor.expert_id=ier.id
and eor.tenant_id = ier.tenant_id
left join
sys_organ so
on so.id=eor.monitor_organ_id
and so.tenant_id = ier.tenant_id
LIMIT 0,
10

排序后
select
ier.id,
eor.id cid,
eor.sort,
ier.title,
ier.summary,
ier.expert_desc,
ier.proposal,
eor.status,
ier.tenant_id,
eor.level_one_code,
eor.cycle_id,
eor.monitor_organ_id,
eor.project_id,
so.name monitorOrganName
from
index_expert_reviews ier
left join
expert_organ_relation eor
on eor.expert_id=ier.id
and eor.tenant_id = ier.tenant_id
left join
sys_organ so
on so.id=eor.monitor_organ_id
and so.tenant_id = ier.tenant_id
order by
CONVERT( monitorOrganName USING GBK) ASC LIMIT 0,
10

可以发现虚拟在最下面了
边栏推荐
- 黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
- 全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
- 【API接口工具】postman-界面使用介绍
- [C language] qsort function
- Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
- Simulation volume leetcode [general] 1314 Matrix area and
- QT: the program input point xxxxx cannot be located in the dynamic link library.
- MFC on the conversion and display of long string unsigned char and CString
- JWT-JSON WEB TOKEN
- Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
猜你喜欢

[no app push general test plan

Summary of anomaly detection methods

oscp raven2靶机渗透过程

Construction and integration of Zipkin and sleuth for call chain monitoring

浅谈专项测试之弱网络测试

E - 食物链

ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
![[postman] test script writing and assertion details](/img/65/6520fe78bb2b3ff99f16d09ea8c0d1.png)
[postman] test script writing and assertion details

P问题、NP问题、NPC问题、NP-hard问题详解

MySQL之基础知识
随机推荐
Simulation volume leetcode [general] 1218 Longest definite difference subsequence
进程和线程的理解
Postman核心功能解析-参数化和测试报告
Simulation volume leetcode [general] 1091 The shortest path in binary matrix
Summary of anomaly detection methods
通过修改style设置打印页样式
Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
sourceInsight中文乱码
模拟卷Leetcode【普通】1062. 最长重复子串
Selenium source code read through · 9 | desiredcapabilities class analysis
Simulation volume leetcode [general] 1447 Simplest fraction
模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
Pat (Grade B) 2022 summer exam
E - 食物链
【无App Push 通用测试方案
MySQL之数据类型
模拟卷Leetcode【普通】1314. 矩阵区域和
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
模拟卷Leetcode【普通】1218. 最长定差子序列
模拟卷Leetcode【普通】1143. 最长公共子序列