0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

MongoDB doesn’t natively support SQL, but it supports the OP’s query. The problem is not the lack of SQL—it is that DynamoDB’s query engine doesn’t support server-side aggregations of any kind.
@MatthewPope I didn't mean to connect those two statements as cause and effect. I'll clarify.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.