select * from #t1 a
cross apply (
select b.prodid,max(daytime)dt from ProductRateMarginLog b
where b.daytime<a.daytime and a.prodid=b.prodid
group by b.prodid
)
b
select * from #t1 a
cross apply (
select b.prodid,max(daytime)dt from ProductRateMarginLog b
where b.daytime<a.daytime and a.prodid=b.prodid
group by b.prodid
)
b