2
I am developing a SQL Server Database, which lists two tables:
Where a process has N movements, I need to return the following data: all Process that have the column Irrecuperavel(int) = 1 and that the "last" date entered in the Progress table for that Process DataAnda(date) be it >= 6 months.
SELECT
A.NumeroProcesso, MAX(A.DataAnda)
FROM Andamento AS A LEFT OUTER JOIN Processo AS P
ON A.NumeroProcesso = P.NumeroProcesso
WHERE
(P.Irrecuperavel = 1) AND
(DATEDIFF(MONTH, A.DataAnda, GETDATE()) >= 6)
GROUP BY A.NumeroProcesso
My past returns but does not filter for the longest date.

perfect! thanks good job.
– Evandro