当前位置:网站首页>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

可以发现虚拟在最下面了
边栏推荐
- Simulation volume leetcode [general] 1218 Longest definite difference subsequence
- Simulation volume leetcode [general] 1109 Flight reservation statistics
- Postman核心功能解析-参数化和测试报告
- MFC关于长字符串unsigned char与CString转换及显示问题
- Leaflet map
- G - Supermarket
- Overview of three core areas of Mathematics: algebra
- B - The Suspects
- Isam2 and incrementalfixedlagsmooth instructions in gtsam
- 對數據安全的思考(轉載)
猜你喜欢

The latest 2022 review of "graph classification research"
![[API interface tool] Introduction to postman interface](/img/03/c1541fca65dd726fd4bdc8793b605e.png)
[API interface tool] Introduction to postman interface

selenium源码通读·9 |DesiredCapabilities类分析

【Postman】测试(Tests)脚本编写和断言详解

SourceInsight Chinese garbled

Construction and integration of Zipkin and sleuth for call chain monitoring

LeetCode 731. 我的日程安排表 II

Selenium source code read through · 9 | desiredcapabilities class analysis

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

CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
随机推荐
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
测试周期被压缩?教你9个方法去应对
模拟卷Leetcode【普通】1062. 最长重复子串
全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
LeetCode 732. 我的日程安排表 III
模拟卷Leetcode【普通】1219. 黄金矿工
Significance of unit testing
黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
[no app push general test plan
模拟卷Leetcode【普通】1447. 最简分数
对数据安全的思考(转载)
Simulation volume leetcode [general] 1447 Simplest fraction
一文揭开,测试外包公司的真 相
MySQL之基础知识
Win10 cannot operate (delete, cut) files
[postman] test script writing and assertion details
通过修改style设置打印页样式
Thoughts on data security (Reprint)
(中)苹果有开源,但又怎样呢?