I have a review
type with a rating
field that contains a number
from 1 to 5. Now I'd like to calculate the average rating. Relevant schema:
{
name: 'rating',
title: 'Rating',
validation: Rule => Rule.required(),
type: 'number'
},
Sanity recently added arithmetic operations to GROQ, but I'm not sure how to use them and there's very little documentation.
- Is it possible to calculate the sum of all ratings using an arithmetic operation? If so, how?
- Can you also divide the sum by the number of all reviews in the same query?