Subtracting dates <p>I have the following code:</p> <pre><code>SELECT t2.Owner, a.accNumber, a.Rest, dateadd(day,1,MIN(a.Date)), MIN(b.Date) FROM t1 a LEFT JOIN t1 b ON a.accNumber=b.accNumber LEFT JOIN t1 ON a.accountId = t2.accountId WHERE a.Date&lt;b.Date AND a.Rest&lt;&gt;0 AND a.accNumber=b.accNumber GROUP BY a.accNumber, a.Rest, t2.Owner ORDER BY t2.Owner </code></pre> <p>I want to subtract dates in 5 and 4th column <code>(MIN(b.Date) - dateadd(day,1,MIN(a.Date)))</code> and put it as 6th column, but simple <code>DATEDIFF(day, dateadd(day,1,MIN(a.Date)), MIN(b.Date))</code> doesn't work because of LEFT JOINs.</p> <p><img src="https://i.stack.imgur.com/ek54k.png" alt="enter image description here"></p> <p>This is how it should look like. with current code, I can see only first 5 columns, I want to see 6th column either</p> <p><img src="https://i.stack.imgur.com/HGAeT.png" alt="enter image description here"></p> <p>This is how it looks like when I add <code>DATEDIFF(day, 4, 5)</code> to Select statement</p>