clear markdown compare help donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 462221 distinct fiddles created so far.

CREATE TABLE pp ( id int, amount int, currency varchar(4), date_created date, from_date date, thru_date date, product_code varchar(2) );
 hidden batch(es)


INSERT INTO pp VALUES (101, 21, 'DUSD', '2018-01-01', '2018-01-01', '2018-01-20', '01'), (101, 22, 'USD', '2018-01-02', '2018-01-21', NULL, '01');
 hidden batch(es)


CREATE TABLE so ( date_created date )
 hidden batch(es)


INSERT INTO so VALUES ('2018-01-25');
 hidden batch(es)


SELECT pp.*, so.date_created sale_date_created FROM pp JOIN so ON so.date_created >= pp.date_created AND so.date_created BETWEEN COALESCE(pp.from_date, so.date_created) AND COALESCE(pp.thru_date, so.date_created);
id amount currency date_created from_date thru_date product_code sale_date_created
101 22 USD 2018-01-02 2018-01-21 01 2018-01-25
 hidden batch(es)