0
votes

I have a DynamoDB with items as follows

ID     TotalCount   SuccessCount   FailedCount

1         10            5              5

1         5             3              2

1         5             2              3

Using DynamoDB AWS Java SDK (e.g using DynamoDBQueryExpression or DynamoDBScanExpression or any other DynamoDB API), how can I get count of TotalCount, SuccessCount and FailedCount for ID = 1.

Equivalent SQL like query will be as follows.

SELECT COUNT(TotalCount), COUNT(SuccessCount), COUNT(FailedCount)
FROM TABLE
WHERE ID = 1;

Any help will be appreciated.

1

1 Answers

1
votes

DynamoDB doesn't natively support this type of aggregation and it also does not support SQL so you can't use any SQL queries. You'd have to scan/query the table, retrieve the relevant rows, and then sum the columns in your application.

If column aggregations are really important to your application and you're committed to NoSQL then you might want to try to maintain them independently but it's a difficult problem to solve.

Depending on your programming language, there may also be third-party options like RazorSQL or DynamoDB.SQL.