当前位置:网站首页>SQL针对字符串型数字进行排序
SQL针对字符串型数字进行排序
2022-04-23 06:27:00 【阿兵哥哥】
背景:
因项目需要,需对字符串型数字进行排序
方法一:
-
原理:将长度一致的字符串先排序,再按照字符串的ASCII码排序。
-
SQL语句:
SELECT transactionGmv6Months FROM company WHERE categoryId=127726077 ORDER BY LENGTH(transactionGmv6Months),transactionGmv6Months; -
查询结果:

方法二:
- 原理:将字符串中不需要的字符先去掉,再转换为数字类型进行排序【推荐】。
- SQL语句:
SELECT transactionGmv6Months FROM company WHERE categoryId=127726077 ORDER BY CONVERT(REPLACE(REPLACE(transactionGmv6Months,'+',''),',',''),SIGNED) DESC - 查询结果:

版权声明
本文为[阿兵哥哥]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Ayue1220/article/details/119388535
边栏推荐
- Redis connection error err auth < password > called without any password configured for the default user
- The difference and application of VR, AR and MR, as well as some implementation principles of AR technology
- Moment. Format of format method function in JS
- 系统与软件安全研究(三)
- SVG中Path Data数据简化及文件夹所有文件批量导出为图片
- SAP TRANSLATE使用数据对象掩码示例
- 防抖和节流
- js案例之求最大值,反转数组,冒泡排序
- 游戏辅助脚本开发之旅
- SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)
猜你喜欢

BTREE, B + tree and hash index

Django uses MySQL database to solve error reporting

js之DOM学习获取元素

SAP ECC连接SAP PI系统配置

Reflection on the systematic design of Android audio and video caching mechanism

设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?

SAP pi / PO rfc2soap publishes RFC interface as WS example

防抖和节流

Authorization server (simple construction of authorization server)

Ogldev reading notes
随机推荐
js之函数的两种声明方式
手游的热更方案与动态更新策略
公共依赖模块common的处理
Date object (JS built-in object)
层次输出二叉树
instanceof的实现原理
King glory - unity learning journey
超级宝典&编程指南(红蓝宝书)-读书笔记
Methods of database query optimization
.NET 5 的新功能 What‘s new in .NET 5
取得所有点列表中的最大值GetMaxPoint
基于NLP的软件安全研究(二)
2. Restricted query
11. Table and library management
Learn to use search engines
对js中argumens的简单理解
SAP PI/PO登录使用及基本功能简介
Reflect on the limitations of event bus and the design and implementation of communication mechanism in component development process
8. Paging query
游戏辅助脚本开发之旅