Skip to content
Advertisement

Tag: window-functions

Date cycle in T-SQL

I need to write a query that displays time intervals that go on without interruption. Example: Input: Output: I think we need to use the function DATEDIFF line by line. The problem is that I don’t know how to access indexes. Or can this problem be solved much easier? Answer This is a type of gaps-and-islands problem. Use a lag()

SQL clean History repeated intermediate values

I’ve noticed that my table has multiple redundant values that should be cleaned, it’s a table that records price changes, so I would like to clean the following way: To this: Also assume that in this case the column id is the same as date. SELECT DISTINCT ON (product, price) won’t work because it would ignore either the product 1

Advertisement