sql - Select closest match -
i trying merge 2 tables (pc mc), statement below yield multiple records mc. i'd query return match in mc cast(pc.ten date) - cast(mc.to date) positive small possible. how do that?
create table test select distinct pc.number, mc.number pc inner join mc on pc.member = mc.member , pc.ned = mc.ned , cast(pc.ten date) between cast(mc.to date) + 1 , cast(mc.to date) + 11 , pc.ned not null , mc.ned not null;
create or replace view test select n1, n2 ( select pc.number n1, mc.number n2, row_number() on (order cast(pc.ten date) - cast(mc.to date) asc) rank pc inner join mc on pc.member = mc.member , pc.ned = mc.ned cast(pc.ten date) - cast(mc.to date) > 0 ) rank = 1
Comments
Post a Comment