Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i have a column that contains data like this:

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
164 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...