title: How to calculate difference between current date and previous date in different rows
body: <p>Hi I want to calculate the difference between dates in different rows using sql teradata assistant </p>
  
  <p>my table look like this</p>
  
  <pre><code>create table test (
      id INT,
      Dx varchar(10)
      Dx_date date);
  
      insert into TEST values(1,'E14','2015-05-03');
  insert into TEST values(1,'E15','2013-05-06');
  insert into TEST values(1,'E15','2016-03-03');
  insert into TEST values(2,'E15','2012-03-04');
  insert into TEST values (3,'E144','2011-03-04');
  insert into TEST values  (3,'E122','2011-02-04');
  </code></pre>
  
  <p>Than to calculate the difference of dates between each row I'm using this code</p>
  
  <pre><code>select id,
              dx, 
              Date_dx, 
              zeroifnull (MDIFF(Date_dx,1,id,dx)
              from TEST
              group by id;
  </code></pre>
  
  <p>But it gaves me wrong results</p>
  
  <p>Thank you for the help</p>