SQLITE order by numeric and not alphabetic

孤街醉人 提交于 2020-08-08 07:15:09

问题


When I order my database SQLITE by Classement I have this :

Classement | Nom
1          | clem
10         | caro
11         | flo
12         | raph
2          | prisc
3          | karim
4          | prout

I would like to get :

Classement | Nom
1          | clem
2          | prisc
3          | karim
4          | prout
10         | caro
11         | flo
12         | raph

Here is my code :

SELECT t.Classement 
FROM tableau t 
WHERE 1 = (SELECT 1 + COUNT (*) FROM tableau t2 WHERE t2.Classement < t.Classement OR ( t2.Classement == t.Classement AND t2.Nom < t.Nom ))

Can anyone help me ? Thank you!


回答1:


You get alphabetic order if the values are strings.

To change the table so that all Classement values are numbers, ensure that the column type is not a text type, and use this:

UPDATE tableau SET Classement = CAST(Classement AS NUMBER);



回答2:


I guess column Classement is not an integer but character.

So try this SELECT * FROM tableau order by cast(Classement as integer)



来源:https://stackoverflow.com/questions/46467140/sqlite-order-by-numeric-and-not-alphabetic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!