0
I have a table:
aluno1 - data 1 student 1 - date2 student 2 - date1 student 2 - date2
And I want my query to return:
aluno1 - date1 (date + recent) aluno2 - date2 (date + recent)
How do I give a distinct only in the student with the latest date? I tried according to that reply, but I’m not getting the syntax right
select *
from (
select ac.cod_matricula,
he.cod_usuario_log,
he.dt_atualiza_log,
he.txt_ip_log,
he.cod_usuario_log_del,
he.dt_atualiza_log_del,
RANK() OVER(PARTITION BY ac.cod_matricula) rnk
from OW.HIST_HISTORICO HE, OW.ALUNO AC
where ac.cod_aluno_curso = he.cod_aluno_curso
and he.cod_usuario_log = '1234567'
--and extract(YEAR from he.dt_atualiza_log) = 2018
order by he.dt_atualiza_log desc )
where rnk = 1
From what I understand you want to always return the latest date of the dt_actualiz_log column correct? If this is the case, there is no need for Partition by, I could solve using a Max grouping on the date and adding the other fields in the group by.
– Confundir