Asc order in a column of numbers

Here is the query below, and I want the point column to be in ASC order, but when I execute the next query, it does not match ASC. See Result below.

SELECT * FROM `bonus` ORDER BY `bonus`.`points` ASC 

It returns the following data:

 id referrer_id points created modified 1 10 100 2013-06-01 00:00:00 2013-06-18 00:00:00 2 30 15 2013-06-01 00:00:00 2013-06-18 00:00:00 3 20 45 2013-06-01 00:00:00 2013-06-18 00:00:00 

But I want the dots column to be in ASC, like this

 id referrer_id points created modified 1 10 100 2013-06-01 00:00:00 2013-06-18 00:00:00 2 20 45 2013-06-01 00:00:00 2013-06-18 00:00:00 3 30 15 2013-06-01 00:00:00 2013-06-18 00:00:00 
+4
source share
2 answers

Try the following:

 SELECT * FROM bonus ORDER BY CAST(points AS INT) ASC; 
+1
source

I think the point column is a varchar data type, so you need to manually cast to an integer, you will get the answer

 SELECT * FROM `bonus` ORDER BY cast(bonus.points As int) asc Create Table #Temp1(Id varchar(10)) insert into #Temp1 values(1) insert into #Temp1 values(10) insert into #Temp1 values(2) Select Top 10 * from #Temp1 Order by Id 1 10 2 Select Top 10 * from #Temp1 Order by cast(Id As int) 1 2 10 Drop Table #Temp1 
+2
source

Source: https://habr.com/ru/post/1488491/


All Articles