金仓sql SELECT ROUND(CAST(IFNULL(( SELECT count(*) "online" FROM cms_all_status WHERE deptid = '4195bacc64614089ba98ff75d2482fbb' AND detecttime BETWEEN (now() - INTERVAL'120 SECOND') AND CURRENT_TIME ) / ( SELECT count(*) total FROM cms_all_status WHERE deptid = '0214b47ce0f144278d9ac8e5a51c06c9' ), 0) AS NUMERIC), 2) online_rate 出现 SQL 错误 [42883]: 错误: 操作符不存在: timestamp without time zone <= time with time zone Hint: 没有匹配指定名称和参数类型的操作符. 您也许需要增加明确的类型转换. Position: 151 At Line: 5, Line Position: 68
时间: 2024-01-27 20:02:36 浏览: 87
金仓Kingbase日常运维SQL汇总.pdf
根据错误信息看,是因为在比较 `detecttime` 和 `CURRENT_TIME` 时,类型不匹配导致的。`detecttime` 是 `timestamp without time zone` 类型,而 `CURRENT_TIME` 是 `time with time zone` 类型。可以通过将 `CURRENT_TIME` 转换成 `timestamp without time zone` 类型来解决这个问题,具体可以使用 `CAST(CURRENT_TIME AS timestamp without time zone)` 来进行强制类型转换,修改后的 SQL 如下:
```
SELECT ROUND(CAST(IFNULL((
SELECT count(*) "online"
FROM cms_all_status
WHERE deptid = '4195bacc64614089ba98ff75d2482fbb' AND detecttime BETWEEN (now() - INTERVAL'120 SECOND') AND CAST(CURRENT_TIME AS timestamp without time zone)
) / (
SELECT count(*) total
FROM cms_all_status
WHERE deptid = '0214b47ce0f144278d9ac8e5a51c06c9'
), 0) AS NUMERIC), 2) online_rate
```
阅读全文