简体   繁体   English

查询返回意外值

[英]Query returns unexpected value

When I use the following query SQLite is returning the following:当我使用以下查询时,SQLite 返回以下内容:

在此处输入图片说明

So as TotalSafeSanitationServices2000 goes from, say, 80 - 79 the next value in descending order will be 8. The data type is set to TEXT and I assume this is why, but from what I've read data type is less important in SQLite, but it is more difficult to change.因此,当 TotalSafeSanitationServices2000 从 80 - 79 降序排列时,下一个值将是 8。数据类型设置为 TEXT,我认为这就是原因,但从我读过的数据来看,SQLite 中的数据类型不太重要,但更难改变。

Is there a simple solution to this?有没有简单的解决方案?

I am using DB browser for SQLite我正在为 SQLite 使用数据库浏览器

Sorting rules are different from strings and numbers;排序规则不同于字符串和数字; string-wise, '89' is less than '9' (because it starts with '8' , which is less than '9' ).字符串方面, '89'小于'9' (因为它以'8'开头,小于'9' )。

You can CAST() your strings to numbers for sorting:您可以将字符串CAST()为数字以进行排序:

order by cast(TotalSafeSanitationService2000 as integer)

I would suggest modifying your data structure to store numbers as numbers.我建议修改您的数据结构以将数字存储为数字。 You are starting to see the problems that arise when not using the correct datatype (there are more to come such as artithmetic operations).您开始看到不使用正确数据类型时出现的问题(还有更多的问题,例如算术运算)。 SQLite has limited functionalities to modify a table, so you would need to recreate it, move the data, and drop the old one. SQLite 修改表的功能有限,因此您需要重新创建它、移动数据并删除旧的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM