Conditional Group Aggregation
Updated
Problem statement
Group rows, compute conditional counts and aggregate values, then apply filters to the grouped result.
Interpretation
For this exercise, assume the supplied samples table contains row_id, cohort, value and quality.
- Keep only rows whose
value >= 0and whosequalityis exactlyokorbad. - Group the retained rows by
cohort. Count all retained rows asrow_count, count only retainedokrows asok_count, and sum retainedvalueastotal_value. Identical values in different rows count separately. - Return only cohorts with
row_count >= 3,ok_count >= 2andtotal_value >= 100. - Return columns
cohort, row_count, ok_count, total_valuein that order, with rows sorted bycohortin ascending order. If no cohort qualifies, return these columns and no rows.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
samples
| Column | Type | Nullable | Description |
|---|---|---|---|
| row_idPK | Integer | No | — |
| cohort | Text | No | — |
| value | Integer | No | — |
| quality | Text | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| cohort | Text | No | — |
| row_count | Integer | No | — |
| ok_count | Integer | No | — |
| total_value | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- There are 0 to 2,000 input rows. All fields are non-null, and row_id values are unique.
- Each value is an integer between -1,000 and 1,000. Cohort values contain only lowercase English letters or only uppercase English letters per case; quality is case-sensitive text.
- The input may contain groups that have no qualifying rows. Return one row per qualifying cohort.
More Stripe Online Assessment questions
- Asynchronous Event ProcessingOA · Seen Nov 2026
- Maximum Game Score with Fixed Forward JumpsOA · Seen Nov 2026
- Reliable LLM Call with Independent Retry BudgetsOA · Seen Nov 2026
- Request Routing SystemOA · Seen Nov 2026
- Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
- Chat Billing CalculationOA · Seen Nov 2026
- Deployment Window SchedulerOA · Seen Nov 2026
- Subscription and Usage-Based Billing CalculatorOA · Seen Nov 2026
- Split Tender Part 4 - RefundsOA · PHONE SCREEN · Seen Nov 2026
- Incident MonitorOA · Seen Nov 2026