dynobase-icon
Dynobase

DynamoDB: Query Group By (Guide w/ Code Examples)

Rafal Wilinski

Provided by Rafal Wilinski

Last updated: October 23rd, 2026

DynamoDB does not implement SQL GROUP BY. For a small dataset, scan and aggregate in application code; for recurring reports, maintain counters with Streams or query an exported dataset.

Install @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb, use an ES module on a supported Node.js runtime, and configure an AWS Region and credentials. The examples use an existing Orders table with String keys pk and sk unless an index or timestamp key is described.

import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, ScanCommand } from "@aws-sdk/lib-dynamodb"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); const counts = new Map(); let lastKey; do { const page = await ddb.send(new ScanCommand({ TableName: "Orders", ProjectionExpression: "#status", ExpressionAttributeNames: { "#status": "status" }, ExclusiveStartKey: lastKey, })); for (const item of page.Items ?? []) { if (typeof item.status === "string") counts.set(item.status, (counts.get(item.status) ?? 0) + 1); } lastKey = page.LastEvaluatedKey; } while (lastKey && Object.keys(lastKey).length > 0); console.log(Object.fromEntries(counts));

This counts items by a String status attribute. It reads every item and does not produce a snapshot under concurrent writes.

Reference: AWS Scan API. For related access patterns, see DynamoDB query examples.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.