I have a database like this:
ID | Day | Value |
---|---|---|
1 | 2021-09-01 | a |
2 | 2021-09-01 | b |
3 | 2021-09-01 | c |
4 | 2021-09-02 | d |
5 | 2021-09-02 | a |
6 | 2021-09-02 | a |
7 | 2021-09-02 | e |
8 | 2021-09-03 | c |
9 | 2021-09-03 | f |
10 | 2021-09-03 | a |
I'd like to count how many different rows I have daily and all time, but the all time uniqueness should count only with the date before (the business logic behind that I'd like to count if the user is new). so I'd like to see this output:
Day | Daily Unique Counts | All Time Unique Counts |
---|---|---|
2021-09-01 | 3 | 3 |
2021-09-02 | 3 | 2 |
2021-09-03 | 3 | 1 |
notes: 2021-09-02 the Daily Unique Counts counting 'd', 'a' and 'e' but the All time Unique Counts won't count the 'a' at all because it was counted the day before.
Right now I can get the Daily Unique Counts right but I can't figure it out how can I count the All time Unique Counts column.
SELECT Date, COUNT (DISTINCT id) AS Daily Unique Counts,
FROM table
GROUP BY 1
ORDER BY 1 DESC
I hope it's clear what I'd like to see, pls help with this because it's driving me crazy :)