I want to select only records from 2020, so I’m using a sub query here.
I don’t see the point for the suqbuery at all. If you want records of 2020, then:
select ...
from fsm
where data_date >= '2020-01-01' and data_date < '2021-01-01'
Note that this uses direct filtering against column data_date
. This is much more efficient than applying a date function on the column, as in your original predicate: year(data_date) = 2020
, which requires applying the function to the entire dataset before the filtering can happen, and precludes the use of an index.
CLICK HERE to find out more related problems solutions.