0
← Exercises/
Aggregations•7 of 12
AggregationsIntermediatePRO

Daily Active Workspaces & Action Frequency

Scenario

Product analytics wants to evaluate engagement depth across organization subscription plans. They need to count how many distinct workspaces are active and determine the average actions performed per active workspace.

Task
Group records in `app_events` by `subscription_tier`. Calculate: 1. `subscription_tier` 2. `total_events`: Total count of event records 3. `unique_workspaces`: Count of distinct `workspace_id` values 4. `avg_events_per_workspace`: `ROUND(CAST(COUNT(*) AS NUMERIC) / COUNT(DISTINCT workspace_id), 1)` Order results by `total_events` descending.
Expected Output Format

Plan tiers showing total events, unique active workspaces, and events per workspace.

Input Tables & Sample Data0 tables
Loading database schema...
Need a hint?
query.sql|Local Sandbox
Loading SQL editor...
Click "Run" or press ⌘ + Enter to execute your query

About the “Daily Active Workspaces & Action Frequency” SQL Problem

Business Scenario

Product analytics wants to evaluate engagement depth across organization subscription plans. They need to count how many distinct workspaces are active and determine the average actions performed per active workspace.

Expected Output & Criteria

Plan tiers showing total events, unique active workspaces, and events per workspace.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM

This challenge executes directly against the following relational schema in your browser:

CREATE TABLE app_events (
        event_id INT PRIMARY KEY,
        workspace_id INT NOT NULL,
        subscription_tier VARCHAR(30) NOT NULL,
        event_action VARCHAR(50) NOT NULL
      );

Target SQL Clauses & Operators

GROUP BYCOUNTROUND

Want more Aggregations practice?

Explore the full syllabus of 12 exercises, syntax guides, and interview pitfalls.

View Aggregations Track→