如圖,我想是實現按取每一種幣別的最新的那條匯率;
先按幣別分組 篩選出你小於指定日期的最大時間和幣別集合
select cur_Id,max(pre_time)as preTime from fc_excrate_adjust fe where fe.pre_time<=to_date('2020-05-11', 'yyyy-MM-dd') group by cur_Id
在用原表內連接 用條件聯立
select a.cur_id,a.old_exchange_rate,a.new_exchange_rate from fc_excrate_adjust a
inner join (select cur_Id,max(pre_time)as preTime from fc_excrate_adjust fe where fe.pre_time<=to_date('2020-05-11', 'yyyy-MM-dd')
group by cur_Id)bs on bs.cur_Id=a.cur_id and bs.preTime = a.pre_time;
這樣獲取的集合即是每個幣種在指定日期前最新匯率的集合了