sql - Join Table by previous top (max) date -


i have following problem: have 2 tables, 1 accounts table transactions in (there can multiple transactions in sigle day), table account balances (where balance @ end of day recorded; since tranactions don't occur everyday balance table has date 'gaps' like: 2014-01-05 800 usd next row 2014-02-03 600 usd). need join tables initial balance of day (max previous date in balance table).

select client_id, transaction_id, amount, date transactions 

balance table:

select client_id, date, balance balance 

i need like

select *  transactions t     inner join balance b on b.client_id = t.client_id , t.date > b.date  

(here should previous max date)

select *  transactions t     inner join balance b             on b.client_id = t.client_id            , t.date = (select max (bl.date)                          balance bl                          t.client = bl.client_id                          , bl.date < t.date) 


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -