How to define a conversation pattern in SQL?

Actually, this does not apply to SQL, and I doubt that the "conversation template" is the correct name, but I could not come up with a better header.

To simplify, imagine you got a huge stream of ints. The task is to find the pattern A.{1;max_n}A: int satisfies the pattern if n (> 0) other ints follow it, then the original int again, and n <= max_n.

Example:

...
1
4 <--
7 \
3  > n = 3
3 /
4 <--
2
...

Here int is 4repeated with 3 arbitrary ints between them, so for max_n <= 3 the pattern is executed for the value 4.

The question is, how do you determine which integers in a huge data dump follow this pattern? What interests me most is the algorithm itself, but an example in SQL or C # is also welcome.

, , - ints, , .

+3
2

(#) (++), .

, . , , . .

+1

, SQL , , .

-, SQL, . , :

SELECT DISTINCT
  t1.number
FROM 
  table t1, table t2
WHERE
  (t1.rownumber-t2.rownumber) <= @max_n AND
  (t1.rownumber-t2.rownumber) >=1 AND
  t1.number = t2.number AND
0

Source: https://habr.com/ru/post/1757793/


All Articles