Answer the question
In order to leave comments, you need to log in
How to count holes?
good afternoon,
a task to stretch the brain.
there is a plate
d
---
1
2
3
5
6
7
10
11
15
21
you need to calculate how many holes there will be, namely (4) - I will show where
d
---
1
2
3
-----------
5
6
7
-----------
10
11
-----------
15
-----------
21
need to write request
Answer the question
In order to leave comments, you need to log in
SELECT count(
CASE WHEN NOT exists(
SELECT null FROM table t2 WHERE t2.d = t1.d + 1
) THEN 1 END
) - 1
FROM table t1;
SELECT count(t1.d) - 1
FROM table t1
LEFT JOIN table t2 ON t2.d = t1.d + 1
WHERE t2.d IS NULL;
select sum(1)-1 from tt t1 where not exists (select * from tt where id - 1 = t1.id);
I'll give you my solution too.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question