0

I have data in the format (Before sorting)

"8 - 15days"    "0"
"0 - 24hrs" "0"
"above 30days"  "0"
"2 - 7days" "0"
"16 - 30days"   "0"

I need to sort the data in order like this(After sorting)

"0 - 24hrs" "0"
"2 - 7days" "0"
"8 - 15days"    "0"
"16 - 30days"   "0"
"above 30days"  "0"

Can anyone help me to sort the data. I tried order by but it is not sorting the data in the way I need.

1
  • Please add your schema? Commented Jul 17, 2020 at 10:13

1 Answer 1

1

If the column with the text in it is called x, you could use

ORDER BY x !~ '^[[:digit:]]',
         regexp_replace(x, '^([[:digit:]]*).*$', '0\1')::integer
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.