The AVG function is a MYSQL function which we can use to find the average value of a numerical field.

It can be used in a similar way to SUM.

Example

We have four tickets where a numerical value has been entered in custom field #1

avg5.png

To find the average value of this field we could then simply run the query below:

SELECT AVG(tickets.custom_data[1]) AS 'Average field value'
FROM tickets

This would output the below:

avg2.png

It's often useful to have a GROUP BY field with this data as well.

For example you could group by agent to find the average value per agent using the below:

SELECT AVG(tickets.custom_data[1]) AS 'Average field value'
FROM tickets
GROUP BY tickets.agent

To output:

AVG3.png

The matrix function can also be used to good effect with this function.

Published: 17/07/2019

Last updated: 26/07/2019