T-SQL: Find the first and last date (+1) for each price change

5 pts.
Tags:
T-SQL
T-SQL 2008
I have a table of price and date like:
Price Date
3.20000000 2018-01-14
3.20000000 2018-01-18
3.20000000 2018-01-19
4.00000000 2018-02-10
4.00000000 2018-02-11
4.00000000 2018-02-12
5.10000000 2018-02-16
3.20000000 2018-03-11
4.00000000 2018-03-15
 
I wish to get the first date for every time the price changes also the last date (plus one day) before the price changes. So from the table above the result should be something like:
Please note, that the price goes up and down and the same price can occur several time as above.
 
Price Date
3.20000000 2018-01-14
3.20000000 2018-01-20
4.00000000 2018-02-10
4.00000000 2018-02-13
5.10000000 2018-02-16
5.10000000 2018-02-17
3.20000000 2018-03-11
3.20000000 2018-03-12
4.00000000 2018-03-15
4.00000000 2018-03-16
I wish to use self join to achieve this. 
Thanks
 


Software/Hardware used:
SQL Server 2008

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    Post a sample of what you have tried. We are glad to help you with fixing code but won't write it for you. You will learn more by trying it and reinforcing the knowledge.
    113,720 pointsBadges:
    report
  • Subhendu Sen
    At least you tried to write the SQL for this assignment? You have to try yourself and write some piece of code and run it properly. If there is an error, you can come back for more help. Search on the net as 'w3schools' & you can get more help.
    118,690 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: