I'm looking for the syntax to SUM a TAG given a Start and End date time... (pi oledb)
I have tried, I have come the conclusion that I have just lost my mind..
You can use SUM function as below
SELECT sum(value) as PIOLEDBSUM FROM [piarchive]..[picomp]
WHERE tag = 'sinusoid' AND time BETWEEN '*-2h' AND '*'
Take a look at piarchive..pitotal and set the calcbasis to EventWeighted
WHERE tag = 'sinusoid'
AND time BETWEEN 't' AND 't+1h' AND calcbasis = 'EventWeighted'
ok... Thanks gentlemen for your response!
"SELECT sum(value) as pioledbsum FROM piarchive..picomp WHERE tag = 'AB_FU2_ML2_BSH1_FLOW___EPV' AND time BETWEEN '*-5h' AND '*'"
I was trying picomp2 earlier and failed
Thank you very much!
Ensure the value is converted to a numeric value and try this:
select sum(cast(value as float32))
where tag = '<tag>'
and time >= '<date start>' and time <= '<date end>'
However, understand, this will give an event weighted sum only; it will be like extracting the values into a spreadsheets and getting the sum of a column.
Thank you Tim. will do!.
I know you have great answers already. Please allow me to point out the difference between the suggestion from Dan Fishman and the one from Lal Babu Shaik. When querying piarchive..pitotal, you get the total returned while the other solution means retrieving and summing all values client side. I consider querying piarchive..pitotal a little more elegant because it means less traffic on the network and may even return slightly faster.
Thank you Gregor. I will be using this suggestion as it is reasonable to conclude that going forward our network will only grow and traffic is a concern.
Retrieving data ...