查询按tm排序取得时间范围内最新的信息
使用分析函数(partition by
(select * from
select g.code,g.tm ,g.z nwz,g.q nwq,g.Z-h.WRZ NWCMWRZ,
row_number() over (partition by g.stcd order by g.tm desc) rn
from RIVER_R g
left join RVFCCH_B h on g.CODE=h.CODE
where g.TM>=To_date('2011-07-14 08','yyyy-mm-dd hh24-mi-ss')
and To_date('2011-07-14 13','yyyy-mm-dd hh24-mi-ss')>g.tm
)
where rn=1