Sorting Text as a Number
Posted: Fri Dec 27, 2013 8:07 pm
Hello,
Is there an option on the order by statement that I can use to sort text values like numbers?
I have a varchar column in a table like this:
Here's what I get when I use an order by:
But I want the results to be:
10
50
100
150
200
250
300
350
400
950
1000
Thank you
Is there an option on the order by statement that I can use to sort text values like numbers?
I have a varchar column in a table like this:
Code: Select all
dbadmin=> \d tsort;
List of Fields by Tables
Schema | Table | Column | Type | Size | Default | Not Null | Primary Key | Foreign Key
----------+-------+--------+-------------+------+---------+----------+-------------+-------------
snowfall | tsort | num | varchar(10) | 10 | | f | f |
(1 row)
Code: Select all
dbadmin=> select * from tsort order by num;
num
------
10
100
1000
150
200
250
300
350
400
50
950
(11 rows)
10
50
100
150
200
250
300
350
400
950
1000
Thank you