title: Oracle Analytical Function?
body: <p>For the given table below, how can we find the customer whose name appears 3 times consecutively.</p>
  <pre><code>+---------+-----------+
  | CUST_ID | CUST_NAME |
  +---------+-----------+
  | 1       | SAM       |
  +---------+-----------+
  | 2       | SAM       |
  +---------+-----------+
  | 3       | SAM       |
  +---------+-----------+
  | 4       | PETER     |
  +---------+-----------+
  | 5       | PETER     |
  +---------+-----------+
  </code></pre>
  <p>Desired_Output</p>
  <pre><code>+-----------+
  | CUST_NAME |
  +-----------+
  | SAM       |
  +-----------+
  </code></pre>
  <p>Table Definition:</p>
  <pre><code>create table Customer
  (
    cust_id int,
    cust_name varchar2(20)
  );
  
  insert into customer values (1, 'SAM');
  insert into customer values (2, 'SAM');
  insert into customer values (3, 'SAM');
  insert into customer values (4, 'PETER');
  insert into customer values (5, 'PETER');
  </code></pre>
  <p>Code Tried so far</p>
  <pre><code>Select distinct cust_name from (
  select
  cust_id,
  cust_name,
  lag(cust_name,1,0) over (order by cust_id)  as prev_cust_name,
  lead(cust_name,1,0) over (order by cust_id) as next_cust_name
   from customer) a
   where a.prev_cust_name=a.next_cust_name;
  </code></pre>
  <p>I believe we can do this by using lead/lag to get the previous and next row. Although my solution gives the desired output but i don't think this is correct solution.</p>