--环比去年 and substr(last_sum.dbilldate,1,4) = to_char(add_months(to_date(substr(tmp.dbilldate,1,7),'yyyy-mm'),-12),'yyyy')
row_number() over()取最新版本
select iversion
from so_saleorder
select tmp.pk_order
from (select pk_order,
row_number() over(partition by vbillcode order by nversion desc) as rn
from po_order
where dr = 0
and vbillcode = ' vbillcode
') tmp
where tmp.rn = 1
select * from ent_contract