Home > Software design >  first three months from signed date
first three months from signed date

Time:08-30

I have columns id, signed_date, begin_date and have this query:

select id, signed_date, count(*)
FROM table t1
WHERE   is_ever = 'true'
AND   signed_date >= '2021-01-01'
group by id, signed_date

I need from signed_date to or had within the first three months delay.


If had then in DB are begin_date since when start delay. can't use CTE

CodePudding user response:

the interval function should help:

select id, signed_date, count(*)
FROM table t1
WHERE   is_ever = 'true'
AND   signed_date = '2021-01-01' and begin_date between signed_date AND signed_date   interval '3 months'
group by id, signed_date
  • Related