【发布时间】:2021-03-05 04:52:55
【问题描述】:
我想在 Grafana 中创建一个这样的表格面板:
+------------+--------------+------------------+
| Name | Access level | Max Access level |
+------------+--------------+------------------+
| Tony Stark | 5 | 5 |
+------------+--------------+------------------+
这可以通过 SQL 查询来完成。我有 MySQL 作为数据源。
我有称为机器和人员的数据库。 在 db 机器中,我有单个机器的表。
表格有 id 和 json 对象作为列。
machines.machine_1
+----+---------------------------------------------+
| id | payload (JSON) |
+----+---------------------------------------------+
| 1 | { |
| | "rack": { |
| | "0": { |
| | "internal": "20.42706840974966" |
| | } |
| | }, |
| | "personel": { |
| | "id": "0xb7c9bd9bc1f7d852", |
| | "access_level": "5", |
| | "access_level_max": "5" |
| | }, |
| | "information": { |
| | "ID": "machine_1" |
| | } |
| | } |
+----+---------------------------------------------+
然后我在 db personel 中有一张带有 personel 的表。
personel.personel
+----+--------------------+------------+------+-------+----------+----------+-------------+
| id | hex | name | post | shift | superior | location | designation |
+----+--------------------+------------+------+-------+----------+----------+-------------+
| 1 | 0xb7c9bd9bc1f7d852 | Tony Stark | CEO | NULL | NULL | NULL | NULL |
+----+--------------------+------------+------+-------+----------+----------+-------------+
现在, 我需要根据来自 json 对象的十六进制键从 personel 表中获取数据 在 machine_1 中。
我设法这样做了:
SELECT
name as "Name"
FROM personel.personel
WHERE exists(
SELECT
json_extract(payload, '$.personel.id')
FROM machines.machine_1 as Table_A
ORDER BY arrived desc
LIMIT 1
)
我不知道,如何创建一个查询,这将导致 3 列,其中名称是从 personel.personel 读取的,由 machines.machine_1 中 json 对象的值十六进制标识,其余值直接来自machines.machine_1中的json对象。
+------------+--------------+------------------+
| Name | Access level | Max Access level |
+------------+--------------+------------------+
| Tony Stark | 5 | 5 |
+------------+--------------+------------------+
如果这是处理此类事情的不正确方法,请告诉我。 我想我可以重做解决方案,但由于其他原因,我想坚持使用 JSON 对象。
感谢您的任何帮助。
最好的问候。
【问题讨论】: