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

Create query to get count of uncompleted calls

There is table waiter_log as Call with call-id ‘f27de4f’ started in 9010 and finished in 9003 because there is a record with proceed_wait = 0 for call-id=’f27de4f’ Call with call-id ‘asdf231′ started in 9010, still proceed in 9002 and not finished yet because there is no record with proceed_wait = 0 for call-id=’asdf231’ Similarly for call with call-id ‘rete125’ there

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

Merge groups of consecutive rows in T-SQL and sum values from each group

Updated 10/08/2019: @Gordon Linoff: I have tried to applied your solution but I realized that is not working as expected. I have added an example with expected result with comments here (https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=1b486476d6aeab25997f25e66ee455e9) and I would be grateful if you could help me. — I have a table of transactions with schema: Here are some row examples: What I want is

Advertisement