select fire_lat ptz_lat, fire_lon ptz_lon, count(1) count from enbogis.bis_all_fire_alarm_index where 1=1 and districtcode is not NULL and alarm_time is not null and source_lon is not null and source_lat is not null and fire_lon is not null and fire_lat is not null此代码中is not null 失效
时间: 2023-07-16 18:13:42 浏览: 117
火灾报警器代码
这段 SQL 语句中的 `is not null` 条件失效可能是因为该表中的某些字段允许为空,因此在查询时即使这些字段的值为 `null`,查询也不会受到影响。如果想要确保查询结果中这些字段的值不为 `null`,可以使用 `coalesce` 函数将这些字段转换为一个非空的值,例如:
```
SELECT
COALESCE(fire_lat, 0) AS ptz_lat,
COALESCE(fire_lon, 0) AS ptz_lon,
COUNT(1) AS count
FROM
enbogis.bis_all_fire_alarm_index
WHERE
districtcode IS NOT NULL
AND alarm_time IS NOT NULL
AND source_lon IS NOT NULL
AND source_lat IS NOT NULL
AND fire_lon IS NOT NULL
AND fire_lat IS NOT NULL
```
在上面的示例中,如果 `fire_lat` 或 `fire_lon` 为 `null`,则它们会被转换为 0。如果你不想将这些字段转换为特定的值,也可以使用 `coalesce` 函数将它们转换为一个非空的字符串或其他数据类型。
阅读全文