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 stock exchange trading company manages a table that documents the USD to ILS currency exchange rate, at the beginning and end of each day.
Each row in the table specifies the following data: Serial number, date, the USD exchange rate at the beginning of the day, and its rate at the end of the day.
For example, on January 4th, 2016, the USD exchange rate was 4.3 at the beginning of the day, and 4.1 at the end of the day.
CREATE TABLE rates (rate_id int identity(1,1), rate_date date, start_rate_value decimal (4,2), end_rate_value decimal (4,2)