Forum

Posted by Shiva, June 5, 2023, 9:44 a.m.

Q15 Why do we need +1 in the avg(extarct ())

In the question to get average number of rental days in the question, I see in the solution AVG( EXTRACT ( days  FROM (return_ts - rental_ts))+1)  is used but i dont understand why we need the +1 ? Without the +1 also we return the same result.

Answers

Hi Shiva,

That's a great question, +1 basically mimicks the use cases of rental payments.

For example: if you return your rented dvd after 7 days plus a few hours late, you will be charged for 8 days.

The same applies for car rentals. If you return the car x days  and a few hours, you will be charged x+1 days.

Hope that makes sense,

Leon

This makes sense Leon, thanks for the explanation. 

Shiva, June 5, 2023, 12:02 p.m.
SQLPad user avatar

Leon (949)

June 5, 2023, 11:25 a.m.