Skip to content
Advertisement

SQL – Calculate number of occurrences of previous day?

I want to calculate the number of people who also had occurrence the previous day on a daily basis, but I’m not sure how to do this?

Sample Table:

Desired Output:

Edit: Added desired output. The output count should be unique to the ID, not the number of date occurrences. i.e. an ID 5 can appear on this list 10 times for dates 2/23/2020 and 2/24/2020, but that would count as “1”.

Advertisement

Answer

Use lag():

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement