I have a column in a table that contains seat numbers that look like this: 10D, 4E, 12A..etc
I am trying to take off the ending letters, and order them by ascending order. My code below takes off the ending letter, but it doesn’t order them correct.
It orders them like this:
10
12
13
3
4
7
8
select distinct rtrim(col_name(col_name, 1, LENGTH(col_name) - 1)) as "Row" from table
order by rtrim(substr(col_name, 1, LENGTH(col_name) - 1));
You would need to cast to a numeric type to get numerical ordering. For example
Assuming your RDBMS supports cast to
int. If MySQL you could useUNSIGNEDin place ofint