; with cte as
(
select h.[terminal], h.[date], rd_tamount, t.rd_type, t.rd_code,
rn = row_number() over (partition by h.[terminal], h.[date], t.rd_type, t.rd_code order by rd_ttrans desc)
from [dbo].[REGHIST] h
inner join [dbo].[REGDTAIL2] t on h.[terminal] = t.[terminal]
and h.date = t.rd_date
where h.[date] between '2015-12-12' and '2015-12-13'
)
select *
from cte
where rn = 1
1 Like
Thanks Khtan
got the result from your advice