Create 90-day filter before a period

Asked

Viewed 463 times

1

I need you to bring back the results that completed 90 days within an informed period.

For example, I have the ability to do:

DT_INICIO_REAL <= (sysdate-90), I will have as a result 90 days from the current date

or DT_INICIO_REAL BETWEEN :DT_INICIO AND :DT_FIM I will have results of the period informed.

But I need to "merge" the two things, I want you to report a period, for example 01/10/2017 until 10/10/2017 and bring me the lines in which DT_INICIO_REAL complete 90 days within the reported period.

1 answer

2


How about:

SELECT
    *
FROM
    TABELA
WHERE
    DT_INICIO_REAL BETWEEN to_date('01-OCT-2017') and to_date('10-OCT-2017') AND
    (trunc(sysdate) - DT_INICIO_REAL) >= 90;

See working on Sqlfiddle

  • You made me go after that function trunc. I found a use here at Sopt and the documentation therein: https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions201.htm

  • 1

    sysdate returns the local day and time. The function trunc() serves to convert a type TIMESTAMP for DATE, "truncating" the hours, minutes and seconds.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.