4
Use the form below:
SELECT COD_CLIENTE,MAX(DT_ATUALIZACAO) FROM TABELA GROUP BY COD_CLIENTE;
Depending on the situation, use MIN() instead of MAX();
I hope I’ve helped! :)
4
6
Use the form below:
SELECT COD_CLIENTE,MAX(DT_ATUALIZACAO) FROM TABELA GROUP BY COD_CLIENTE;
Depending on the situation, use MIN() instead of MAX();
I hope I’ve helped! :)
4
I thought the following, as you want the latest update according to the date so you want the highest value date.
So I did the same SELECT but I added a clause WHEREwho uses the function MAX() to fetch the latest date:
SELECT CD_CLIENTE,
DT_ATUALIZACAO,
FROM
TBL_CLIENTES_SOFTWARE_HOUSE_ATUALIZACAO t1
WHERE
t1.DT_ATUALIZACAO = (SELECT MAX(t2.DT_ATUALIZACAO) FROM TBL_CLIENTES_SOFTWARE_HOUSE_ATUALIZACAO t2 WHERE t2.CD_CLIENTE = t1.CD_CLIENTE)
2
Using SELECT DISTINCT you will return only a single value for each customer(CD_CLIENTE) if it happens again, even then, would not solve your problem.
How you want to recover the client code along with the larger one(MAX()) update date. You can recover as follows.
SELECT CD_CLIENTE,
MAX(DT_ATUALIZACAO)
FROM TABELA GROUP BY CD_CLIENTE
Browser other questions tagged sql sql-server
You are not signed in. Login or sign up in order to post.