AVG(amount) divides by the count of non-NULL amount values in each group.

highlighted = computed this step

Input table

Use the same sales rows so the average can be checked against the sum.

Sales\text{Sales}
Salesorder_idcategoryamounto1book20o2book35o3pen5o4penNULLo5pen20

Group query

Group by category and average the non-NULL amounts.

GROUP BY category, AVG(amount)\text{GROUP BY category, AVG(amount)}
GROUP BY category averagegroup_byarity 2 rows 2Salesarity 3 rows 5

Grouped output

Both averages are exact rational values because they are not whole numbers.

averages by category\text{averages by category}
Grouped outputcategoryavg_amountbook55/2pen25/2