Grafana查询
Select UNIX_TIMESTAMP(created_at) as time_sec,
metric_value as value,
'Metric Value' as metric
from lumenis_db.telemetry
where $__timeFilter(created_at)
收到以下错误:
Value column must have numeric datatype, column: value type: string
如何通过查询将metric_value从字符串转换为数字?
编辑
我的SQL:
CREATE TABLE lumenis_db.telemetry (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
created_at DATETIME(3) NOT NULL,
device_type VARCHAR(35) NOT NULL,
device_serial VARCHAR(35) NOT NULL,
metric_name VARCHAR(35) NULL,
metric_value VARCHAR(35) NULL
);
答案 0 :(得分:1)
如果metric_value
包含作为存储为String
的数字的值,则可以使用MySQL的CONVERT
函数,例如:
SELECT UNIX_TIMESTAMP(created_at) as time_sec,
CONVERT(metric_value, UNSIGNED) as value,
'Metric Value' as metric
FROM lumenis_db.telemetry
WHERE $__timeFilter(created_at)
Here是CONVERT
函数的文档。
答案 1 :(得分:-1)
SELECT UNIX_TIMESTAMP(created_at) as time_sec,
CAST(metric_value as SIGNED integer) as value,
'Metric Value' as metric
FROM lumenis_db.telemetry
WHERE $__timeFilter(created_at)
成功了