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

可以发现虚拟在最下面了
边栏推荐
- Idea new UI usage
- Digital triangle model acwing 1015 Picking flowers
- Testing of web interface elements
- 数据库-当前读与快照读
- 在线问题与离线问题
- Full link voltage measurement: building three models
- 把el-tree选中的数组转换为数组对象
- Réflexions sur la sécurité des données (réimpression)
- E - 食物链
- 全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
猜你喜欢
随机推荐
Manhattan distance and Manhattan rectangle - print back font matrix
在uni-app中使用腾讯视频插件播放视频
模拟卷Leetcode【普通】1062. 最长重复子串
MySQL之基础知识
Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
B - The Suspects
Simulation volume leetcode [general] 1249 Remove invalid parentheses
数据库-当前读与快照读
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
Aike AI frontier promotion (2.13)
Testing of web interface elements
sourceInsight中文乱码
The pit encountered by keil over the years
Basic knowledge of error
keil MDK中删除添加到watch1中的变量
[postman] collections - run the imported data file of the configuration
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
全链路压测:构建三大模型
Postman核心功能解析-参数化和测试报告
Overview of three core areas of Mathematics: geometry








