Hello, I am working with data from one dairy farm. I want to subtract the value of the column "calving_date" only if the column abort_dim = 0 to the calving_date of the previous lactation and within the same ID. For example from ID 1, I want to subtract 2/25/2018 - 1/30/2018 because it has a 0 on the abort_dim column on lactation 3 and the previous lactation was 2. I have been trying to use SQL, but since I have three grouping conditions I am struggling to get want I want. This is sample data, my original data has thousands of rows. Any help will be greatly appreciated.
... View more