GQL
does not support GROUP BY
and aggregate functions like COUNT
, MAX
. That is why it is called GQL
instead of SQL
. Check GQL Reference for more information.
Google App Engine does not allow aggregate functions, it is a trade-off that is made for scalability. So if you need to perform aggregate functions over your data set you have to do this by yourself. If it is a simple counter you can store a counter and increment it every time you add a record that matches the criteria. For more complex aggregate functions with fuzzy dimensions (for grouping), you have to come up with your custom solution. There is not a simple answer.
Nick's suggestion could be one of the solutions; having a task to check the conditions and calculate the aggregate functions regularly. But it will never be accurate, it will always be something approximate. That is also why Google does not show the exact number of results that matches a specific search query because they don't know, at least they don't want to calculate it, they just provide an estimate.