Task
You are given raw customer feedback records from an Orange survey export. Write a PostgreSQL query that returns the number of valid feedback submissions by channel, excluding rows with missing customer_id, blank feedback_text, or non-positive rating. Sort the result by the count descending, then by channel ascending.
Schema
| column | type | description |
|---|
| feedback_id | INT | Unique feedback record identifier |
| customer_id | INT | Customer identifier; can be NULL in bad records |
| channel | VARCHAR(50) | Source channel such as app, web, or store |
| feedback_text | TEXT | Free-text feedback message |
| rating | INT | Rating from 1 to 5; invalid rows may contain 0 or negative values |
| submitted_at | DATE | Date the feedback was submitted |
Sample data
| feedback_id | customer_id | channel | feedback_text | rating | submitted_at |
|---|
| 1 | 101 | app | Great service | 5 | 2024-05-01 |
| 2 | 102 | web | | 4 | 2024-05-01 |
| 3 | NULL | store | Helpful staff | 5 | 2024-05-02 |
| 4 | 103 | app | Slow response | 2 | 2024-05-03 |
| 5 | 104 | web | NULL | 1 | 2024-05-03 |
| 6 | 105 | store | Easy to use | 0 | 2024-05-04 |
Expected output
| channel | valid_feedback_count |
|---|
| app | 2 |
| store | 1 |