Compare strings as numbers in SQLite3

∥☆過路亽.° 提交于 2020-01-03 08:39:12

问题


I have the following query in SQLite:

SELECT * FROM t1 ORDER BY t1.field

Where t1.field is a text column containing numbers. Is it posible to force SQLite to consider the values of t1.field as numbers instead of strings (whithout doing ALTER TABLE)? Right now the sort is a pure string one, so 10 goes before 2.

Thank you.


回答1:


Well, found a solution:

SELECT * FROM t1 ORDER BY t1.field + 0

The + 0 part seems to force conversion to number



来源:https://stackoverflow.com/questions/4204319/compare-strings-as-numbers-in-sqlite3

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