Sum of values in same table


I’m running a grafana which gets input from a db that contains my Amperage registrations.
my db is structured like this:
Time Phase Type Value
1 L1 Irms 5
1 L2 Irms 1
1 L3 Irms 2

I want my graph to show that for time=1 (or in the end, automatically as I select the timerange of course), that the total value = 8

SELECT sum(Value) FROM “flukso” WHERE (“Type” = ‘Irms’ ) AND $timeFilter LIMIT 0
This query doesn’t show anything… can someone help me out please?

Never saw the “LIMIT 0” part in MS SQL

Don’t know where that came from. Removing it doesn’t solve the issue. ps: I created the base query using the grapical interface and then checked the “text” version, which included that ‘limit’

Grafana night be defaulting to it’s Value flag,
and as well the formatting of Grafana to SQL might be more like below

SELECT sum( f.Value ) 
FROM   flukso f
WHERE  f.Type = 'Irms'
AND    $__timeFilter(f.Time)
SELECT sum( f.Value ) value,
Type metric,
getdate() as time
FROM   flukso f
group by Type

Do you want sum of all types?

1 Like

Hi, I want a sum of all 3 “lines”. Error of your code:
message:“InfluxDB Error: error parsing query: found value, expected FROM at line 1, char 23”

message:“InfluxDB Error: error parsing query: found f, expected ; at line 2, char 15”

this is the error with your code… :frowning:

so you have Influxdb but you have tagged your question with mssql.

1 Like

ah SORRY :confused:
it’s an influxdb indeed, but the query behind the grafana was (I thought) mssql…

sorry for the confusion

what is time column with value 1?

sorry, don’t understand what you mean…

the data is realtime import from my electric grid.
as you can see, there is a timestamp, unit (Amps), value, phase (L1, L2 or L3), L1P and L2P are not used for the moment.

Time Phase Type Value
1 L1 Irms 5
1 L2 Irms 1
1 L3 Irms 2

Time = 1 what does that mean?

ah ok, it just means timestamp 1

L1 has at T1 = 5
L1 has at T2 = 5.1

so it means at time X (or t = 1), L1 = 5, L2 = 1 and L2 = 2; so the shown result should be 5+1+2 = 8

is this more clear?

timestamp of 1, fascinating! is that initial singularity, just before big bang happened? the beginning of time :scream:

timestamp is usually timestamp :slight_smile: either in nanoseconds or actual date time.

hahaha, I took Hawking’s course and have found the origin of the universe… like he said, black matter was found when you find the source of black holes :smiley:

it’s a unixtimestamp :slight_smile: but instead of typing 15 numbers I just type 1 :wink:

1 Like

For some reason i am hitting a wall with my influxdb

Glad I’m not the only one…