我无法在grafana中执行此操作(减去两个查询)并且能够使用postgres查询(包括grafana宏)执行此操作:
SELECT (first / second * 10000 - 10000) as spread, time FROM ( SELECT $__timeGroupAlias("time",$__interval,previous), avg(bid) AS "first" FROM bbo_20s WHERE $__timeFilter("time") AND market = 1 GROUP BY time ) AS e FULL JOIN ( SELECT $__timeGroupAlias("time",$__interval,previous), avg(bid) AS "second" FROM bbo_20s WHERE $__timeFilter("time") AND market = 2 GROUP BY time ) AS c USING ("time") ;
结果看起来像这样,性能非常好: