Skip to content
Advertisement

Grafana change SQL query for a totalization of each data point

I have a grafana dashboard that charts a bunch of data on 2 query’s, this is one below:

SELECT
    "time" AS "time",
    metric AS metric,
    value
FROM 
    slipstream_volttron
WHERE
    $__timeFilter("time") AND
    metric ~ 'slipstream_internal/slipstream_hq/.*/SA-F$'
ORDER BY 1,2

And this is the other query:

SELECT
    "time" AS "time",
    metric AS metric,
    value
FROM 
    slipstream_volttron
WHERE
    $__timeFilter("time") AND
    metric ~ 'slipstream_internal/slipstream_hq/.*/Discharge Air Flow$'
ORDER BY 1,2

Would anyone know how I could modify this into one SQL expression for a totalization? Instead of 50 different lines on my chart, just one line of all variables added together. The data is air flow readings and I am trying to figure out how to just plot a totalized air flow reading of all data, hopefully that makes sense for anything */Discharge Air Flow and .*/SA-F

Advertisement

Answer

I’m guessing your database isn’t MSSQL as I don’t recognise ~ as a valid comparison operator so my answer is a bit of a guess based on what would work for MSSQL. I think this should give you the results you are looking for:

SELECT
    "time" AS "time",
    SUM(value)
FROM 
    slipstream_volttron
WHERE
    $__timeFilter("time") AND
    (metric ~ 'slipstream_internal/slipstream_hq/.*/Discharge Air Flow$'
        OR metric ~ 'slipstream_internal/slipstream_hq/.*/SA-F$')
GROUP BY time
ORDER BY 1
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement