Difference between two queries over x time

I have two seperate queries which produce a count result each

Is there a way to do simple calculations like the difference between Query A and B =

Query A minus Query B in the past 60 minutes

This is what id like to do.

Welcome

What is your data source for these results?

They are both from the same mariadb database, is this possible or even minus the result of two panels

Keep it simple and do it in one query. Let me spin up my grafana hang on

Ok Thank you very much.

you welcome. what kind of visualization do you have this on?

sample query using what is called cross tab (since you did not provide sample table(s) with data, I just went with my own assets table from snipeit (Try the Demo - Snipe-IT Free open source IT asset management)

SELECT REGION_1, REGION_2 ,
REGION_1 - REGION_2 as difference
FROM (
select COUNT(CASE WHEN warranty_months = 36 THEN 1 END) AS REGION_1,
     COUNT(CASE WHEN warranty_months <> 36 THEN 1 END) AS REGION_2
FROM assets
) AS latte

Then the visualization in table is

1 Like

i clearly do not know sql very well but this is what i have

SELECT count() as known FROM spawnpoint WHERE despawn_sec
UNION
SELECT count(
) as unknown FROM spawnpoint WHERE despawn_sec is null ;

Only its naming count as known but the second one not as unknown

look at the sample query I provided and see if you can grok it. I want you to fly on your own baby :wink: :bird:

SELECT Known, Unknown ,
Known - Unknown as difference
FROM (
SELECT count(*) FROM spawnpoint WHERE despawn_sec is not null as Known,
count(*) FROM spawnpoint WHERE despawn_sec is null as unknown


:expressionless:

try it using the CASE statement I posted. Replace table names with yours and column names with yours.

Come on, you got this!

got it thanks, now to get it to show the difference in the last 60 min

please provide a lot of sample data as follows

csv

datefield,despawn_sec
2022-05-25,null
2022-05-26,'salamander'

or sql

--ddl
create table sample(timeline timestamp,despawn_sec varchar(50)

--dml
insert into sample
values('2022-05-02 13:00:00',null)

etc but we need tons of data because we do not have access to your database. providing this data will help us help you emulate your data in our mariadb

is there a way to send this to you in a message?

let’s do it here. that way others can chime in to help you solve this issue also

you can use online data generators such as https://www.mockaroo.com/

I managed to get everything i need for now, hope the example above helps sombody out, Thanks for all the help, you rock!

1 Like