#706

Active SCD2 record version on a given date

Rosbank's DDS layer is a classic SCD2 warehouse on Greenplum/Postgres. Each record carries a DATERANGE validity interval (half-open): the active version's upper bound is infinity. The analyst wants a snapshot of every contract on a given date. Give me a contract snapshot as of 2024-03-15: exactly one row per contract — the version whose valid interval covers that date. Contracts that had no active version on that date should be left out. For dt_to, return upper(valid) or NULL when the upper bound is infinity.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.

dt_tostatusdt_fromrate_pctcontract_id
2024-04-01OPEN2024-02-0111.00401
NULLOPEN2024-01-159.90402
2024-04-15OPEN2024-03-157.50405
Rosbank

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid