Skip to content
Advertisement

Tag: sliding-window

Data aggregation by sliding time periods

[Query and question edited and fixed thanks to comments from @Gordon Linoff and @shawnt00] I recently inherited a SQL query that calculates the number of some events in time windows of 30 days from a log database. It uses a CTE (Common Table Expression) to generate the 30 days ranges since ‘2019-01-01’ to now. And then it counts the cases

Find start and end dates when one field changes

I have this data in a table When ever the value in FIELD_D changes it forms a group and I need the min and max dates in that group. The query shoud return The examples that I have seen so far have the data in Field_D being unique. Here the data can repeat as shown, First it is “N” then

Advertisement