SELECT ORG_NO, 利润总额, NVL(LAG(a.利润总额) OVER (PARTITION BY a.ORG_NO ORDER BY a.数据日期 DESC),0) AS 上年利润总额, 数据日期 FROM( SELECT ROW_NUMBER() OVER(PARTITION BY TO_CHAR(DATA_TIME, 'YYYY') ORDER BY DATA_TIME DESC, STAT_TIME DESC) rn, ORG_NO, --当前年最新利润总额 NVL(TOTAL_PROFIT,0) AS 利润总额, TO_CHAR(DATA_TIME,'YYYY-MM-DD') AS 数据日期 FROM BRAIN.DWS_MANAGE_PROFIT )a WHERE a.rn = 1
结果: