← Problems|

4. NPS Survey Response Rate by Channel

MediumAggregationsPostgreSQL 18
Table: nps_surveys
+-------------+-------------+
| Column Name | Type        |
+-------------+-------------+
| survey_id   | int         |
| customer_id | int         |
| channel     | varchar(20) |
| sent_at     | date        |
| score       | int         |
+-------------+-------------+

survey_id is the unique key for this table. Each row contains record details for this enterprise dataset.

The customer experience team sends NPS surveys by email, in-app prompt, and SMS. Before they cut the SMS budget, they want to know how many surveys each channel actually gets answered, not just how many it sends.

Every survey sent is a row in nps_surveys. When a customer has not answered, score is NULL. Return one row per channel: 1. channel 2. surveys_sent: number of surveys sent 3. responses: number of surveys that were answered 4. response_rate_pct: responses as a percentage of surveys sent, rounded to 1 decimal place 5. avg_score: average score of the answered surveys, rounded to 1 decimal place Order by channel ascending.

Return the result table ordered as specified. The result format is in the following example.

Example 1:
Input:
Preparing sample rows...
Output:
Calculating benchmark target...
Explanation:

One row per channel with surveys_sent, responses, response_rate_pct, and avg_score, where unanswered surveys (NULL score) count as sent but not answered.

Constraints:
  • Query must utilize clause(s): GROUP BYCOUNTROUND
  • Result order matters (tie-breakers and sort order must be strictly preserved).
  • Database: PostgreSQL 18, running in your browser.

About this problem

The business question

The customer experience team sends NPS surveys by email, in-app prompt, and SMS. Before they cut the SMS budget, they want to know how many surveys each channel actually gets answered, not just how many it sends.

Expected result: One row per channel with surveys_sent, responses, response_rate_pct, and avg_score, where unanswered surveys (NULL score) count as sent but not answered.

What you will practice

GROUP BYCOUNTROUND

Tables

CREATE TABLE nps_surveys (
    survey_id INT PRIMARY KEY,
    customer_id INT NOT NULL,
    channel VARCHAR(20) NOT NULL,
    sent_at DATE NOT NULL,
    score INT
  );

More Aggregations practice

17 problems in this topic, with key concepts and common mistakes.

View topic