title: Query that is getting average, maximum, and minimum value of days between two dates in each year
body: <p>I have a table of boats renting:<br>
  RENTING:<br>
  - RentDate PK<br>
  - ReturnDate,<br>
  - BoatId<br>
  and other not needed here fields<br><br></p>
  
  <p>I need to make a query that will return four columns:<br>
  - Year<br>
  - Average number of days of renting this year<br>
  - Maximum number of days of renting this year<br>
  - Minimum number of days of renting this year<br><br></p>
  
  <p>For now i have this query:<br></p>
  
  <pre><code>SELECT 
  YEAR(RentDate), 
  AVG(DATEDIFF(DD, RentDate, ReturnDate))  AS AVERAGE, 
  MAX(DATEDIFF(DD, RentDate, ReturnDate)) AS MAXIMUM, 
  MIN(DATEDIFF(DD, RentDate, ReturnDate)) AS MINIMUM  
  FROM RENTING
  WHERE YEAR(RentDate) = YEAR(ReturnDate)
  GROUP BY YEAR(RentDate)
  </code></pre>
  
  <p>The problem is that i am thinking about the possibility when the rent is started in the end of the year, and it is finishing in another year - RentDate Year != ReturnDate. I think this query doesn't include this posibility.</p>