sql >> Base de Datos >  >> RDS >> Oracle

Unión automática de Oracle a partir del valor mínimo (meses-año) para cada partición

Utilice MIN() como función de ventana:

select t.*,
       (case when col2 < add_months(min(col2) over (partition by col1), 3)
             then col3
        end) as imputed_col3
from t;

Nota:Si col2 no es una fecha, puedes convertirla:

select t.*,
       (case when to_date(col2, 'YYYYMM') < add_months(min(to_date(col2, 'YYYYMM')) over (partition by col1), 3)
             then col3
        end) as imputed_col3
from t;