Skip to content
Programming101
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

Learn everything about programming

Leetcode Consecutive Numbers problem solution

YASH PAL, 31 July 2024

In this Leetcode Consecutive Numbers problem solution, we need to write an SQL query to find all numbers that appear at least three times consecutively. Return the result table in any order.

Leetcode Consecutive Numbers problem solution

Topics we are covering

Toggle
  • Problem solution.
  • Problem solution in MYSQL.
  • Problem solution in Oracle.

Problem solution.

select distinct num as ConsecutiveNums
from
(select num, id - cast(row_number() over (partition by num order by id) as SIGNED) rdiff
from
logs)t
group by num,rdiff
having count(num)>=3

Problem solution in MYSQL.

with df as (
    select id
        , num
        , lag(num) over (order by id) as prev_num
        , lead(num) over (order by id) as next_num
    from logs
    )
select distinct num as `ConsecutiveNums`
from df
where num = prev_num
    and num = next_num

Problem solution in Oracle.

select distinct num ConsecutiveNums from
(select num,lead(num,1) over(order by ID) next_num,lead(num,2) over(order by ID) next_next_num
from logs)
where num = next_num and next_num = next_next_num;

coding problems solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes