pgsql按varchar字段排序(desc降序、asc升序)
varchar类型是字符串,因此
不转换前(按字符串排序):1,10,2,3,4,41,5
转换后(按数值排序):1,2,3,4,5,10,41
– eg:SELECT * from table ORDER BY CAST(file1 AS DECIMAL) ASC;
-- cast(test_file as decimal) :将字段test_file 的字段类型varchar转换为decimal(十进制\小数)
SELECT * FROM test_table order by cast(test_file as decimal) asc;