Calculating average from SQL, creating a table?

Hi there,

I have a triggered transaction group that stores the last 60 minutes of data from a machine (purges data older than an hour). I’d like to take this data and calculate the mean continually as the table updates. What’s the best way to go about this? I’m assuming I need to query the database at a set rate, put that data somewhere, and use the “mean” expression? Seems that the mean expression expects a table column though, correct? I can’t seem to figure out how to get the table to work with this…

Any better ways of doing this? I’m a newbie to Ignition and SQL, so I wouldn’t be surprised if I was approaching this incorrectly :slight_smile:



Hi Adam,

I would tend to carry out this type of grouping function (max, min, average etc.) in the relational database. With MySQL for example, you would use the AVG function to return the average of a particular field from the database. Just create a DB tag with a SQL query like the following:SELECT AVG(Temperature) FROM MyData WHERE Machine_name='Machine 1'You can then update this DB tag at whatever rate you want e.g. every minute if you are only recording every minute and don’t need to see the update instantly, or every second if you need to see the result of the new reading immediately.

That worked perfect… I figured this was probably easier than I thought! Thanks a million for your help ALtheMan!

You’re welcome :slight_smile: