简体   繁体   中英

where filter between 2 date columns in snowflake sas

The problem is I'm trying to pull in a trdate that is 4 days after the s_date

I'm using sas and created a temp table for a snowflake connection labeled column A. I'm joining a table column b. I have my code as follows

create table post_date as select * from connection to snf(
select distinct
 A.*
, b. PA
, b. tc
, b. trdate
from stemptable as A
    left join table B
        on A.rp=b.PA
where a.s_date between b.trdate and 

I know something has to be +4 on b.trdate but unsure of the correct syntax.

This is where I'm stuck. I'm trying to pull in b.trdate to be 4 days after a.s_date. any assistance would be appreciated.

If you want the trdate to be 4 days after s_date, you want trdate = s_date + 4 days. In SQL the four days are an interval added to the date as in the following query:

select
   s.*
 , b.pa
 , b.tc
 , b.trdate
from stemptable as s
left join table tr on tr.pa = s.rp
                  and tr.trdate = s.s_date + interval '4 days';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM