SQL server- filter by number of times

Hi,
I have data with 100K rows.
I want to check the Repetition of emails from the last week, divided into bulks of 2 days (I mean I want to know if there are any emails that appear more than 3 times in the last two days, per week)

How do I divide it into bulks in the last week?
and how do I get only emails which appear above 3 times?

Thanks!

In the last 2 days is only this week

1 Like

I would create an extra column and use the function lag to find the previous messagedate. I would also create an extra column with rownumber to count the amount of emails send. With those 2 extra columns you can achieve what you want.

LAG (Transact-SQL) - SQL Server | Microsoft Docs

ROW_NUMBER (Transact-SQL) - SQL Server | Microsoft Docs