SELECT Finterid, Fbillno, Fdate, rownum FROM (select Finterid,Fbillno,Fdate, row_number() over(partition by Fbillno order by Fdate desc) as rowNum from icstockbill) k where k.rowNum=1