This is a migrated thread and some comments may be shown as answers.

Group By in Cloud Code

3 Answers 53 Views
Cloud Code
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erick
Top achievements
Rank 2
Erick asked on 10 Dec 2014, 02:41 PM
Hi,

I am trying to do same approach as MsSql in the cloud code:

SELECT item_ID, COUNT(download_ID) AS count_downloads
FROM downloads
GROUP BY item_ID

But i can't find anything from the documentations.
Is there a way to do this query?

I have tried to select all records and filter it by item_ID but it will be slow because the table is very large.

You an idea?

3 Answers, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 10 Dec 2014, 03:44 PM
Hi,

Currently the only approach would be to get the count of the items by filter on item_id and group them programmatically with additional code. Unfortunately, at the current stage the API does not expose an aggregation/grouping utility. 

We do have a feature request for this in our Feedback Portal. We'd love to hear any suggestions about this matter in this forum thread or at the page of the feature request.

Let me know if you have any questions.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Erick
Top achievements
Rank 2
answered on 11 Dec 2014, 11:47 AM
Hmm, this is not really a way to do this.

A alternative way: 
Create a count column in the items table.
On each download is performed, add a download record to the downloads table and add one hit to the count column in items table. 
We will do this way until group feature is added.

Thanks for your help.
0
Anton Dobrev
Telerik team
answered on 11 Dec 2014, 11:59 AM
Hello,

Thank you for your reply.

Yes, you are right, the proposed by you approach would be a more elegant solution. Here you can find a sample about updating a number field from the Cloud Code (if applicable).

Let me know if you have further questions or suggestions.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
Cloud Code
Asked by
Erick
Top achievements
Rank 2
Answers by
Anton Dobrev
Telerik team
Erick
Top achievements
Rank 2
Share this question
or