The trials table has one row per user in an A/B test. group_name is the arm the user was assigned to ('control' or 'treatment') and converted is 1 if the user converted and 0 otherwise. Compute the pooled conversion proportion across both arms. Return a single row with conversions_total (all conversions), users_total (all users), and pooled_p = conversions_total / users_total rounded to 4 decimals.
Input Table(s)
Table trials:
| Column | Type | Meaning |
|---|
| group_name | VARCHAR(20) | Arm the user was assigned to: 'control' or 'treatment' |
| converted | SMALLINT | 1 if the user converted, 0 otherwise |
There is no key column. Each row is one user, and no user appears twice.
Output Contract
Exactly one row with these columns, in this order:
| Column | Type | Meaning |
|---|
| conversions_total | integer | Number of users with converted = 1, across both arms |
| users_total | integer | Number of users (rows) in trials |
| pooled_p | numeric | conversions_total / users_total, rounded to 4 decimal places |
The result has a single row, so no ordering is needed.
Example
Input trials:
| group_name | converted |
|---|
| treatment | 1 |
| control | 1 |
| treatment | 1 |
| treatment | 0 |
| control | 1 |
| treatment | 0 |
| control | 1 |
| treatment | 0 |
| control | 0 |
| control | 0 |
| control | 0 |
| treatment | 0 |
| treatment | 0 |
| treatment | 1 |
| control | 0 |
| control | 0 |
| treatment | 1 |
| control | 0 |
| control | 1 |
Expected output:
| conversions_total | users_total | pooled_p |
|---|
| 8 | 19 | 0.4211 |
Treatment has 4 conversions out of 9 users and control has 4 out of 10, so the totals are 8 conversions and 19 users. 8 / 19 = 0.42105..., which rounds to 0.4211.
Constraints and Clarifications
-
converted
is always 0 or 1 and is never NULL.
-
Assume
trials
has at least one row.
-
The arm does not change the result. Every user counts once in the totals, whichever group they are in.
-
Round to 4 decimal places with half away from zero, which is what
ROUND
does on a
NUMERIC
value.