TOTAL_SHARE_HIS表的结构
根据 cust_acco , prd_code, prd_code_batch 三个字段分组后查询出last_modify_date 最大的一条记录:
select * from (select a.*, row_number() over (partition by a.cust_acco, a.prd_code,a.prd_code_batch order by a. last_modify_date desc) as row_num from total_share_his a ) where row_num = 1;
备注:row_numk=2 就是第二条记录,row_numk between 1 and 5 灵活性比较大。
因为select中字段必须和group by中的对应