Skip to content
Advertisement

subquery calculate days between dates

Sub query, SQL, Oracle

I’m new to sub queries and hoping to get some assistance. My thought was the sub query would run first and then the outer query would execute based on the sub query filter of trans_code = ‘ABC’. The query works but it pulls all dates from all transaction codes, trans_code ‘ABC’ and ‘DEF’ ect.

The end goal is to calculate the number of days between dates.

The table structure is:

I want to execute a query to look like this:

Query:

TIA!

Advertisement

Answer

Use lead():

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