I have atm
table and replenishment
table both have the same atm_id
, atm.ATM_id = replenishment.atm_id
.
So I want to get back every atm.title
. atm.ATM_id
with its last replenishment.rep_datetime
.
Trying to find what did I miss. Thank you for your help
I tried this one
select distinct atm.ATM id, atm.title, cash added1, cash added2, cash added3, cash added4,rep_datetime
from replenishment
inner join atm on atm.ATM_id = replenishment.atm_id
where rep_datetime = (select max(rep_datetime) from replenishment)
order by rep_datetime DESC
Any ideas on this one noting that the result gets one record with the latest date for single value but what I want is to have all ids with their latest date.
Expecting all ids without duplications with their latest/newest date.
2条答案
按热度按时间avkwfej41#
You can use a windowing function for this:
pu82cl6c2#