当前位置:网站首页>MySQL is sorted alphabetically
MySQL is sorted alphabetically
2022-07-06 06:22:00 【Do not let it rot】
Today's test raised a requirement , Sort by the first letter of the field
Because the general database code is utf-8 , His sorting method is to sort according to the English alphabet "a,b,c… "

It can be seen from the above table that , As long as we convert the fields to be sorted into GBK Code and then sort , You can sort by field initials , How can I convert the code into GBK Well ? stay MySQL Functions are provided in CONVERT() , This function can be used to get the value of a type
The usage of this function is CONVERT( Field USING GBK)
for example :
SELECT * FROM table ORDER BY CONVERT(field USING GBK) ASC
The following is my sql Example , My requirements are sorted by the initials of the units
Before no sorting
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

After ordering
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

You can find that the virtual is at the bottom
边栏推荐
- Réflexions sur la sécurité des données (réimpression)
- Delete the variables added to watch1 in keil MDK
- Past and present lives of QR code and sorting out six test points
- JMeter做接口测试,如何提取登录Cookie
- [C language] string left rotation
- [eolink] PC client installation
- [postman] collections configuration running process
- 调用链监控Zipkin、sleuth搭建与整合
- F - true liars (category and search set +dp)
- Thoughts on data security (Reprint)
猜你喜欢
随机推荐
【Postman】测试(Tests)脚本编写和断言详解
Summary of anomaly detection methods
leetcode 24. Exchange the nodes in the linked list in pairs
LeetCode 729. 我的日程安排表 I
LeetCode 1200. 最小绝对差
MFC关于长字符串unsigned char与CString转换及显示问题
G - Supermarket
LeetCode 739. 每日温度
Web界面元素的测试
F - true liars (category and search set +dp)
Simulation volume leetcode [general] 1447 Simplest fraction
记一个基于JEECG-BOOT的比较复杂的增删改功能的实现
Database isolation level
模拟卷Leetcode【普通】1447. 最简分数
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
模拟卷Leetcode【普通】1219. 黄金矿工
Database - current read and snapshot read
[no app push general test plan
E - food chain
Properties file









