SQLite命令由十进制和'未知'值

时间:2016-12-24 15:21:29

标签: sql sqlite

我试图通过他们存储在状态中的值(这是一个varchar 255)在我的SQLite数据库中命令我的值

该字段可以包含任何内容,但对于我选择的entity_id,它将包含十进制数字或'unknown'

所以我尝试了以下查询,但它没有工作:

select 
    state, 
    attributes, 
    created 
from states 
where state <> 'unknown' 
    and (entity_id = 'sensor.speedtest_download' or entity_id = 'sensor.fastcom_download') 
order by cast(state as DECIMAL) DESC
Limit 0,30

如果我将order by退出查询,我会得到如下结果:

"61.8"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-11 19:00:30.842672"
"65.45" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-11 21:30:18.669531"
"65.45" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-11 21:41:30.850441"
"73.5"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-11 22:00:30.919995"
"70.14" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-11 22:00:31.098129"
"91.7"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-11 23:00:30.787601"
"80.72" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-11 23:00:30.951527"
"76.5"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-12 00:00:30.844100"
"74.87" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-12 00:00:31.013408"
"91.7"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-12 01:00:30.838618"
"83.5"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-12 01:00:30.976214"
"92.2"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-12 02:00:30.743759"
"83.71" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-12 02:00:30.899923"
"84.4"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-12 03:00:30.814488"
"73.27" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-12 03:00:30.941021"
"78.9"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-12 04:00:30.751924"
"77.79" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-12 04:00:30.926943"
"90.6"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-12 05:00:30.762564"
"82.41" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-12 05:00:31.452064"
"71.3"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-12 06:00:30.875047"
"64.83" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-12 06:00:31.015236"
"90.9"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-12 07:00:30.770224"
"78.18" "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-12 07:00:30.925578"
"86.2"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Fast.com Download""}"   "2016-12-12 08:00:30.837426"
"61.4"  "{""unit_of_measurement"": ""Mbit/s"", ""friendly_name"": ""Download""}"    "2016-12-12 08:00:30.990303"

使用order by我得到:

database disk image is malformed: select state,  created from states 
where state <> 'unknown' and (entity_id = 'sensor.speedtest_download' or entity_id = 'sensor.fastcom_download') 
order by cast(state as DECIMAL) DESC
Limit 0,30

0 个答案:

没有答案