如何从列中按特定格式排序? [英] How to order by specific format from a column?

查看:89
本文介绍了如何从列中按特定格式排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含如下数据的列:

i have a column that contains data like this:

{Population: 1331415}
{Population: 44234}
{Population: 214124212}
{Population: 222222}

我需要通过{Population:之后的数字,以及另一个名为Name(包含城市名称)的列来对数据库进行排序

i need to order the database by the number after {Population: ,and by another column called Name(it contains names of cities)

推荐答案

一种方法是使用长度和值:

One method is to use the length and the value:

order by length(col) desc, col desc

另一种方法是提取数值并将其转换为数字:

Another is to extract the numeric value and convert it to a number:

order by substring_index(col, ': ', -1) + 0 desc

这篇关于如何从列中按特定格式排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆