Skip to content
Advertisement

Tag: gaps-and-islands

Rank based on cumulative value

I want to rank on ID and value columns based on ascending order of UID. Expected output has to change once value column has a different value than the previous value. Ranks has to restart on each new ID Here is a sample dataset that I have created: Answer I think that the simplest approach to this gaps-and-islands problem is

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