title: Calculate results between columns according different parameters in sql, r or python
body: <p>Hi All I have this problem, I'm looking to calculate the days between Dates, with the following premises:</p>
  
  <ul>
  <li>Status A is the base date, all the calculations have to take this date as a reference (group by ID)</li>
  <li>I must take the older date for status B, C, D</li>
  <li>I must calcule the days and showing in different columns </li>
  </ul>
  
  <p>Ex.</p>
  
  <p><strong>generate the table with R</strong></p>
  
  <pre><code>ColID = c(1, 1, 1, 1, 1, 2, 2, 2)        
  ColStatus = c("A", "B", "B", "C", "D", "A", "C", "C")
  ColDate = c("01/01/2018","02/03/2018", "05/04/2018", "04/05/2018", "04/05/2018", "02/01/2018", "04/03/2018", "05/04/2018")
  data.frame(ColID, ColStatus, ColDate)
  </code></pre>
  
  <p>How I proceed with the calculation</p>
  
  <pre><code>For ColID = 1
  
  Status A = 01/01/2018
  Status B (I Have to select the older one) = 02/03/2018
  Status C = 04/05/2018
  Status D = 04/05/2018
  
  ResultColB = 02/03/2018 - 01/01/2018 = 60
  ResultColC = 04/05/2018 - 01/01/2018 = 123
  ResultColD = 04/05/2018 - 01/01/2018 = 123
  </code></pre>
  
  <p>Result table (in days)</p>
  
  <p><strong>generate the table with R</strong></p>
  
  <pre><code>ColID = c(1,2)
  ResultColStatusB = c(60,0)
  ResultColStatusC = c(123,61)
  data.frame(ColID, ResultColStatusB, ResultColStatusC, ResultColStatusB)
  </code></pre>
  
  <p>The problem can be solved in R, Python or SQL, what recommend me to solve this problem?</p>