Could you help me to calculate proportion of
x
Table
user_id attendance Date
1 1 01.01.2018
2 Null 01.01.2018
3 1 02.01.2018
4 Null 03.01.2018
5 1 03.01.2018
If user has attendance there is 1, otherwise – Null.
Need to calculate percent of attendance during 01.01.18 – 02.01.18. For instance, on 01.01.2018 there were 1 user of two (50%), on 02.01.2018 – 100%.
Tnanks!
Advertisement
Answer
You may try this query:
SELECT
Date,
100.0 * COUNT(attendance) / COUNT(*) AS perc_attendance
FROM yourTable
WHERE Date BETWEEN '2018-01-01' AND '2018-01-02'
GROUP BY
Date;
This assumes that a given user would only appear at most once in attendance for a given date. It also assumes that your Date
column is an actual date column, and not just text.