SQL - ORDER BY not working properly?

前端 未结 4 1450
别跟我提以往
别跟我提以往 2020-12-11 16:15

SELECT test_column FROM test_table ORDER BY test_column gives me this:

1   
12  
123  
2  
3

Why not:

1
2
         


        
4条回答
  •  鱼传尺愫
    2020-12-11 16:44

    The sort is working. It's a lexicographic sort (alphabetical). It appears that that column has a text (char, varchar, ...) type, so the ordering you'll get is textual and not numeric.

    If you want a numerical sort, use a numeric column type (e.g. int). (Or cast the column appropriately.)

提交回复
热议问题