To find the balance at a point in time sql
Download
1 / 2

To Find the Balance at a Point-in-time SQL - PowerPoint PPT Presentation


  • 91 Views
  • Uploaded on

To Find the Balance at a Point-in-time SQL. Account fact. Date. Account. dateKey (FK) branchKey (FK) productKey (FK) accountKey(FK) accountStatusKey (FK) householdKey (FK) balance …. dateKey(PK) fullDate …. accountKey(PK) accountNum ….

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'To Find the Balance at a Point-in-time SQL' - ninon


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
To find the balance at a point in time sql
To Find the Balance at a Point-in-time SQL

Account fact

Date

Account

dateKey (FK)

branchKey (FK)

productKey (FK)

accountKey(FK)

accountStatusKey (FK)

householdKey (FK)

balance

dateKey(PK)

fullDate

accountKey(PK)

accountNum

To find the balance as of a certain date requires finding the last transaction prior to the date

The following assumes the date surrogate keys are “increasing” as the date “increases”


To find the balance at a point in time sql1
To Find the Balance at a Point-in-time SQL

Account fact

Date

Account

dateKey (FK)

branchKey (FK)

productKey (FK)

accountKey(FK)

accountStatusKey (FK)

householdKey (FK)

balance

dateKey(PK)

fullDate

accountKey(PK)

accountNum

SELECT accountNum, balance

FROM fact f, account a

WHERE f.accountKey = a.accountKey

AND f.dateKey =

(select max(g.dateKey)

FROM fact g

WHERE g.accountKey = f.accountKey

AND g.dateKey IN

(SELECT d.dateKey

FROM date d

WHERE d.fullDate <= 'January 5, 2002')

)