Search code examples
sqloracle-sqldeveloper

Select only observations with a date more recent than the 30/6/2021 (dd/mm/yyyy)


I have the following code:

Select Tbl.Fromdate, Tbl.Por, Tbl.Porname, Tbl.Bmref3
From(
Select
To_Char(P.Fromdate, 'dd-mm-yyyy') As  Fromdate, P.Por, P.Porname, W.Bmref3,
, RANK() OVER (PARTITION BY P.Por ORDER BY P.fromdate DESC) AS rank 
From Tmsdat.Climandatecomps W 
Inner Join Tmsdat.Portfolios P On (W.Porik = P.Porik)
Where 1=1
) Tbl
Where 1=1
And Tbl.Rank = 1
;

However, I wish to select only the observations that have a Fromdate more recent than the June 30, 2021. I tried to add Tbl.Fromdate> '30-06-2021' to the WHERE clause, but I did not receive the desired results.

Do you have any suggestions?

Thank you in advance.

Best regards,


Solution

  • You would put the condition in the inner query:

    Select To_Char(P.Fromdate, 'dd-mm-yyyy') As Fromdate, P.Por, P.Porname, W.Bmref3,
           RANK() OVER (PARTITION BY P.Por ORDER BY P.fromdate DESC) AS rank 
    From Tmsdat.Climandatecomps W inner join
         Tmsdat.Portfolios P
         On (W.Porik = P.Porik)
    Where p.FromDate > date '2021-06-30'