Skip to content
Advertisement

Latest value of compared date range? (SQL/Snowflake)

I have values in Table-A like:

And values in Table-B like:

And I want to join the two tables such that I see the most recent cumulative sum of values in Table-B as-of the Date in Table-A for a given Patient.

How would I join these two tables by date to accomplish this?

Advertisement

Answer

First step seems like a basic SQL join:

But instead of a plain sum() you can apply a sum() over():

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement