title: Running recursive query in Vertica
body: <p>I am trying to do the exact same thing as <a href="https://stackoverflow.com/questions/24191937/counting-sequential-events-and-counts-of-sequences-sql">this question</a>. But I am in Vertica, and I am finding no way to carry out the top answer, or the other answers. So basically I have tried <strong>connect by</strong> and sub query <strong>UNION ALL</strong> method, and I don't think Vertica supports it. </p>
  
  <p>Is there any way I can replicate the solution in Vertica? </p>
  
  <p>EDIT: Full Question</p>
  
  <p>I am trying to calculate 30-day readmission chains, which is a sequence of readmissions within 30 days from its previous admission. The following data shows a simplified situation where we have events, rather than admission and discharges. Difference in days between events will identify it as a 30-day readmission, consecutive 30 day readmissions(Chain Len) will be a single chain of readmission (Count).</p>
  
  <p>Sample Data</p>
  
  <pre><code>CREATE TABLE dbo.Events (
      EventID INT IDENTITY(1,1) PRIMARY KEY,
      EventDate DATE NOT NULL,
      PersonID INT NOT NULL
  );
  GO
  INSERT dbo.Events (EventDate, PersonID)
  VALUES 
      ('2014-01-01', 1), ('2014-01-05', 1), ('2014-02-02', 1), ('2014-03-30', 1), ('2014-04-04', 1), 
      ('2014-01-11', 2), ('2014-02-02', 2),
      ('2014-01-03', 3), ('2014-03-03', 3);
  GO
  </code></pre>
  
  <p>Sample Output</p>
  
  <pre><code>EventID EventDate  PersonID CHAIN LEN Count
  ------- ---------- -------- --------- -----
  1       2014-01-01 1        1         1
  2       2014-01-05 1        2         1
  3       2014-02-02 1        3         1
  ------- ---------- -------- --------- -----
  4       2014-03-30 1        1         2
  5       2014-04-04 1        2         2
  ------- ---------- -------- --------- -----
  6       2014-01-11 2        1         1
  7       2014-02-02 2        2         1
  ------- ---------- -------- --------- -----
  8       2014-01-03 3        1         1
  ------- ---------- -------- --------- -----
  9       2014-03-03 3        1         2
  ------- ---------- -------- --------- -----
  </code></pre>