How can I edit the following SQL query to get results for each day and each variant, where I have an A/B/Control test:
SELECT
t.day, t.type AS variant_type, t.clicks,
t2.type AS control, t2.control_clicks
FROM
table1 t
LEFT JOIN
table1 t2 ON t.day = t2.day
AND t2.type = 'control'
Currently data will only come through where there is data for a given day in the from clause. This leads to issues when aggregating the data further down the line.
Current results:
| day | variant | variant_clicks | control | control_clicks |
|---|---|---|---|---|
| 2020-01-01 | a | 1000 | control | 1500 |
| 2020-01-01 | b | 2000 | control | 1500 |
| 2020-01-01 | control | 1500 | control | 1500 |
| 2020-01-02 | control | 1700 | control | 1700 |
Desired results:
| day | variant | variant_clicks | control | control_clicks |
|---|---|---|---|---|
| 2020-01-01 | a | 1000 | control | 1500 |
| 2020-01-01 | b | 2000 | control | 1500 |
| 2020-01-01 | control | 1500 | control | 1500 |
| 2020-01-02 | a | 0 | control | 1700 |
| 2020-01-02 | b | 0 | control | 1700 |
| 2020-01-02 | control | 1700 | control | 1700 |
Any help would be greatly appreciated!