troubleshooting Question

Ratio of successive rows in SQL Server

Avatar of AlHal2
AlHal2Flag for United Kingdom of Great Britain and Northern Ireland asked on
9 Comments2 Solutions54 ViewsLast Modified:
Suppose I have a table where the first column is a date and the second an integer.

2016-06-01    10
2017-02-03    20
2017-07-04    30
2018-03-06    40

I'd like an SQL query to return both columns with an extra column containing the ratio of the previous column to the current column.

2016-06-01    10  Null
2017-02-03    20  0.5
2017-07-04    30  0.666
2018-03-06    40  0.75
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros