This advanced SQL exercise is part of the book: Advanced SQL – Practical Techniques and Use-Cases, which includes 100 day-to-day SQL challenges (and solutions), need-to-know advanced features, and key concepts.
 

A hotel in northern Spain uses the following table to track room orders. Each row in this table specifies: serial number, customer name, check-in date, and check-out date. For example, Kenneth ordered a room on January 1st and stayed there until January 3rd. On January 3rd, a few hours after he left the hotel, he decided to check-in again, and stayed in the hotel until January 7th (for convenience sake, this exercise uses a single customer).


CREATE TABLE registration_log   
(r_id int identity(1,1),   
r_customer varchar(25),   
r_sdate date,   
r_edate date)  
GO

Would you like to read more?