Getting different responses when request different properties(aggregate functions).

When I am trying to query data with different custom properties(aggregate functions) I am getting different results. For example:

private final String PROPERTY_COMMENTS_COUNT = "Count(comments) as commentsCount";
private final String PROPERTY_RATING = "Avg(comments.rating) as rating";
queryBuilder.setProperties(COMMENTS_COUNT, PROPERTY_RATING);

I am getting only object A1, if I do

queryBuilder.setProperties(COMMENTS_COUNT);

I am getting only object B1.If I am changing property to

queryBuilder.setProperties(PROPERTY_RATING);

I am getting A1 again. But should get A1 and B1 for all three request.
APP ID: EF0C71DB-AC58-3DDB-FF94-C9B10FF8C200
Thanks
best,
Nick.

I need an array of counted properties for all my objects.

Nick,

Information about objects included into the responses should be ignored when you use aggregate functions. When you get a count or average these values are calculated for a set of objects (such as the entire table or a group), as a result, individual properties for objects A1 or B1 are irrelevant and should be ignored. The documentation talk about it here: http://take.ms/blxnt

Regards,
Mark

Mark, thanks for your answer, but is it possible to query array of objects and sort them by aggregate function ?

I am sorry, I do not understand the question. Could you please explain with an example?

For example, I have Place table that contains 1…n Comments with rating field. I want to query Places by Avg function of rating field in Comments table of this Place. Basically I want to get all Places and sort them using Avg function.

To get multiple results each containing some average value, you need to use grouping. Only then you can sort grouped values. If you do not use grouping (that is the “groupBy” operator, you will be getting only one data point back. For more information, please see this doc page: https://backendless.com/docs/rest/doc.html#data_data_filtering