12 Replies Latest reply on Feb 19, 2019 10:56 AM by gregor

    Can I obtain the average/max/min of two tags?

    esancha

      Hi all!

      I have not known how to find the answer, so my apologies if it was already answered.
      I need to obtain the average, the maximum and the minimum of two tags together, as if it were just one, is that possible? If so, how?

       

      Thanks in advance.

      Regards.

      Emilio Sancha

        • Re: Can I obtain the average/max/min of two tags?
          esancha

          Sometimes there is nothing better than to write to find the solution to a problem ;-)
          I have come up with a solution, I do not know if it will be the right one, but I think it can be worth
          .

           

          An SQL query using PI Oledb with a subquery that includes two "joined" queries it gives me the solution

           

          SELECT Avg(Value) AS Media, Max(Value) AS Maximo, Min(Value) AS Minimo

           

          FROM (

           

          SELECT time, value FROM piarchive..picomp WHERE Tag = 'FRH:A_055' AND time BETWEEN 'y+6h' AND 't+6h'

           

          UNION

           

          SELECT time, value FROM piarchive..picomp WHERE Tag = 'FRH:A_038' AND time BETWEEN 'y+6h' AND 't+6h'

           

          ) AS Consulta

           

          Of course if someone thinks there is a better solution I am open to suggestions

           

          Thanks again

          Regards.

          Emilio Sancha