当前位置:网站首页>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
可以发现虚拟在最下面了
边栏推荐
- Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
- 黑猫带你学UFS协议第4篇:UFS协议栈详解
- Simulation volume leetcode [general] 1218 Longest definite difference subsequence
- 把el-tree选中的数组转换为数组对象
- 【无App Push 通用测试方案
- 使用Nacos管理配置
- Selenium source code read through · 9 | desiredcapabilities class analysis
- Database - current read and snapshot read
- leaflet 地图
- 全链路压测:构建三大模型
猜你喜欢
(中)苹果有开源,但又怎样呢?
【eolink】PC客户端安装
win10无法操作(删除、剪切)文件
Delete the variables added to watch1 in keil MDK
[no app push general test plan
【MQTT从入门到提高系列 | 01】从0到1快速搭建MQTT测试环境
Career advancement Guide: recommended books for people in big factories
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
LeetCode 732. 我的日程安排表 III
二维码的前世今生 与 六大测试点梳理
随机推荐
JDBC Requset 对应内容及功能介绍
Reading notes of effective managers
keil MDK中删除添加到watch1中的变量
MFC dynamically creates dialog boxes and changes the size and position of controls
Thoughts on data security (Reprint)
[postman] collections - run the imported data file of the configuration
浅谈专项测试之弱网络测试
On weak network test of special test
LeetCode 729. 我的日程安排表 I
Simulation volume leetcode [general] 1062 Longest repeating substring
Testing and debugging of multithreaded applications
MFC 动态创建的对话框及改变控件的大小和位置
数字三角形模型 AcWing 1015. 摘花生
【Postman】Collections-运行配置之导入数据文件
Is the test cycle compressed? Teach you 9 ways to deal with it
数据库隔离级别
Qt:无法定位程序输入点XXXXX于动态链接库。
sourceInsight中文乱码
Simulation volume leetcode [general] 1091 The shortest path in binary matrix
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全