0
select e.nm_equipto as EQUIPAMENTOS
,Max(remessa.dt_uso_inicio) as DATA_REMESSA --,(SELECT MAX(DT_ENTORC_OFICINA) FROM ORCOS)as DATA_ABERTURA
,MIN(dt_entorc_oficina) as DATA_ABERTURA
,o.numero as NÚMERO
,patr.nr_patrimonio as PATRIMÔNIO
,DATEDIFF ( DAY , MAX(remessa.dt_uso_inicio), o.dt_entorc_oficina)as QTD_DIAS
from orcos as o
inner join equipto as e on o.cd_equipto = e.cd_equipto
inner join patrimon as patr on o.cd_patrimonio = patr.cd_patrimonio
inner join est_almox as almox on almox.cd_almox = patr.cd_almox
inner join v_remessa_patrimonio as remessa on remessa.cd_patrimonio = patr.cd_patrimonio
group by o.numero
,patr.nr_patrimonio
,o.dt_entorc_oficina
,patr.cd_almox
,e.nm_equipto
having o.dt_entorc_oficina > max(remessa.dt_uso_inicio)
and count(o.numero) > 1
and patr.cd_almox = '6'
order by o.numero desc
the earliest date in the DATA_ABERTURA column
– Jander Helius
Please don’t keep posting duplicate questions. That won’t help you to get a faster answer. Instead of flooding the site, try to be clearer in your explanation and add details to the existing question. Duplicate link: http://answall.com/q/192170/18246
– Jéf Bueno
@Janderhelius: Could you add above (in the description of the problem) additional information to facilitate understanding of the problem as well as help in posting suggestions? For example, what is the purpose of the query, what contains each table involved etc.
– José Diz