mysql

mysql - Truncated incorrect DOUBLE value: 'undefined'

我是怎么遇到这个问题的?

        我要从多个表里,查询统计数据,保存到统计表里,需要执行下面这种结构的 sql 语句:

                insert into table1 select (select count(*) from t1 where ...) c1, select (select count(*) from t1 where ...) c1

        单独执行 select (select count(*) from t1 where ...) c1, select (select count(*) from t1 where ...) c1 没有问题

        合在一起执行就会出现 Truncated incorrect DOUBLE value: 'undefined'

最后发现原因,是因为:

        子语句 select count(*) from t1 where ... 的 where 条件里,有个   where lat != 0

        而 t1 表里,lat 保存的是 varchar 格式,当 lat 有转不了 DOUBLE 的值时,就会报错:Truncated incorrect DOUBLE value: 'undefined'

解决方式:

        将 where lat != 0 改成 where lat != '0'

至于为什么单独执行 select (select count(*) from t1 where ...) c1, select (select count(*) from t1 where ...) c1 却不报错,就不知道为什么了

原文地址:https://www.cnblogs.com/liaolongjun/p/7863022.html