Skip to content
Advertisement

Tag: gaps-and-islands

Number based on condition

I’m trying to generate a number based on a condition. When there is yes in column ‘Stop’ in the partition of a Client ordered by Start_Date, the Dense Rank has to start over. So I tried several things but it’s stil not what I want. My table with current number and expected number The query I used so far: This

SQL to find start and end date for an ID

I have a table with ID, start_date and end_date columns. Table: I want to write a query to get the following output: Output: Answer You can do a cumulative sum to solve this variation of the gaps-and-island problem: Demo on DB Fiddle: ID | START_DATE | END_DATE -: | :——— | :——— 1 | 01/01/2017 | 01/01/2020 2 | 01/01/2016

Row lumping, cycle dates

I want to look at the lead type and if that type is the same for that row then merge in those dates to fit within one row. I have the below table: Expected Results: How can I get my output to look like the expected results? I have tested withlead lag rank and case expression but nothing worthy of