Is it possible to get count using group by in AO?
Community moderators have prevented the ability to post new answers.
Yes, it should be possible like this:
Query query = Query.select("selected_column").group("grouped_column"); ao.count(YourEntity.class, query);
This results in the following SQL statement:
SELECT COUNT(selected_column) FROM ao_xxxxx_your_entity GROUP BY grouped_column
You can also leave the Query.select() statement blank, which results in SELECT COUNT(*).
Hope this helps
There is a problem with it. It only picks up the first value. Group by should yield in columnCount: columnValue. Current work around we have is we run this query with columnValue in where clause (whick makes group by clause useless).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So to use default count, the only way is like:
Query query = Query.select(); ao.count(YourEntity.class,query)
Can't we only use:
ao.count(YourEntity.class);
??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.