How can I do aggregate counts

13 views
Skip to first unread message

Ilya

unread,
Mar 18, 2013, 4:57:41 PM3/18/13
to twig-p...@googlegroups.com
How can I build a query that has aggregate counts with groupings?

ex.
SELECT count(city) , city FROM customers group by city

Thanks!

John Patterson

unread,
Mar 18, 2013, 5:10:06 PM3/18/13
to twig-p...@googlegroups.com
You can't.  Its a limitation of the datastore.

Two solutions:

Firstly, you could do the count in memory yourself if the number results is small.  So sort by city and just iterate through counting each.

Secondly, you could precalculate if the number of customers is large.  Every time you add or remove a customer update some sort of CountCustomersByCity entity in a transaction.  This entity may only hold a Map<String, Integer>.

--
You received this message because you are subscribed to the Google Groups "twig-persist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to twig-persist...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages