Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Active Objects: Is it possible to get count using group by in AO?

Shailesh Shailesh December 6, 2011

Is it possible to get count using group by in AO?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Remo Siegwart
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 7, 2011

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

Shailesh Shailesh December 14, 2011

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).

0 votes
Raul Gallegos July 30, 2013

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);

??

TAGS
AUG Leaders

Atlassian Community Events