Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
1
Indexable
Never
select max(mat.de_insumo) as de_insumo, mat.cd_upnivel1, max(mat.dt_historico) as dt_aplicacao, mat.cd_safra, u.id_bloco_colheita
            from oti_maturador mat
                left join ( select distinct u1.cd_upnivel1      
                                             ,u1.de_upnivel1
                                             ,u3.id_safra_periodo
                                             ,u2.cd_upnivel2
                                             ,u3.cd_upnivel3
                                             ,s.cd_safra
                                             ,u3.id_bloco_colheita
                             from   oti_upnivel1 u1,
                                    oti_upnivel2 u2,
                                    oti_upnivel3 u3
                                    ,oti_safras_periodo s
                             where  u1.id_upnivel1 = u2.id_upnivel1 and
                                    u2.id_upnivel2 = u3.id_upnivel2 
                                    and u3.id_safra_periodo = s.id_safra_periodo
                                    ) u on (u.cd_upnivel1 = mat.cd_upnivel1 and u.cd_upnivel2 = mat.cd_upnivel2 and u.cd_upnivel3 = mat.cd_upnivel3)
            group by mat.cd_upnivel1, mat.cd_safra, u.id_bloco_colheita;