Hope that helps If I have a table ordered by ID like so: , Another option is a variation of GapsandIslands Example code :
Declare @YourTable Table ([ID] int,[Key] varchar(50))
Insert Into @YourTable Values
(1,'Foo')
,(2,'Bar')
,(3,'Test')
,(4,'Test')
Select ID_R1 = min(ID)
,ID_R2 = max(ID)
,[Key]
From (
Select *
,Grp = IDRow_Number() over(Partition By [Key] Order by ID)
From @YourTable
) A
Group By [Key],Grp
Having count(*)>1
ID_R1 ID_R2 Key
3 4 Test
Select ID_R1 = min(ID)
,ID_R2 = max(ID)
,[Key]
From (
Select *
,Grp = Row_Number() over(Order by ID)
Row_Number() over(Partition By [Key] Order by ID)
From @YourTable
) A
Group By [key],Grp
Having count(*)>1
Share :

How to tryfind element in an infinite ordered sequence?
By : livelongandprosper
Date : March 29 2020, 07:55 AM
I hope this helps you . Here is another possible solution. It is quite similar to what @desco posted, but it is using sequence expressions instead of Seq.tryPick and it also does not need nested option types: code :
let has element input =
seq { for v in input do
if v = element then yield Some v
if v > element then yield None }
> Seq.head
let has element input =
input > Seq.takeWhile (fun x > x <= element)
> Seq.tryFind (fun x > x = element)
let has element = Seq.takeWhile ((>=) element) >> Seq.tryFind ((=) element)

Find next N rows in MySQL table ordered by a not unique column
By : Masoom Rahman
Date : March 29 2020, 07:55 AM
will help you You marked < I am here means you know that is the forth record, so you could just do : code :
SELECT * FROM table ORDER BY char,num LIMIT 4, $N

Given a sequence, find the largest 'reverseordered' subsequence
By : Ali Zergham
Date : March 29 2020, 07:55 AM
With these it helps It is not the sort of problem that is suitable for SQL. It is also poorly phrased. You are really looking for pairs of numbers rather than subsequences, and the size is the distance between the two. It can be solved O(n) by scanning the sequence backwards, for the smallest number after a given point, and its position. This gives {1,2,2,2,2,8) and {0,4,4,4,4,5}. Then scanning this in parallel with the original sequences gives sizes of {0,3,2,1,0,0}, so the largest size is for the pair (6,2), which has a size of 3.

find any increase subsequence with size 3 in an unordered array
By : Backto Basics
Date : March 29 2020, 07:55 AM

Find longest ordered sequence in unordered list
By : user2728934
Date : March 29 2020, 07:55 AM
should help you out Your program runs in O(n^3 log n) time which is quite inefficient. How do we arrive at the O(n^3 log n) figure?

