Grafana 从 table 创建查询变量

Grafana create query variable from table

所以我是 Grafana 的新手,我有一个 table 和一个条形图:

条形图查询如下:

select coalesce(group_name) as group_name,
  sum(sales) filter (where device_type = 'HEAD_PHONES') as HEAD_PHONES,
  sum(sales) filter (where device_type = 'GUITAR') as guitar,
  sum(sales) filter (where device_type = 'XBOX') as xbox,
  sum(sales) filter (where device_type is null ) as other
from test
where area = 'AREA1' <--make this grafana variable
group by coalesce(group_name);

我希望每次用户单击 table 中的一行时,条形图都会使用相同的查询进行更新,但区域会根据单击的行而变化。如果有超过 100 个区域,我如何将其设为 Grafana 变量?

这是数据库:

在 grafana 中有“变量”,转到“仪表板设置”--> 变量,从那里创建类型为“query”的新变量,将其命名为“area”并输入 sql query( select 测试区域),保存它,然后在您的 select 查询中: select ... 其中面积在 ($area).

参考https://docs.timescale.com/timescaledb/latest/tutorials/grafana/grafana-variables/#using-grafana-variables