求帮助,oracle数据库,查询出每个地方的最新时间的那一条数据

select p.* from (select rownum as 序号 ,n.* from (select sitename as 站点名称, RecordTime as 记录时间 ,decode(avg(case item when 211 then value else null end),0,'0.00000',trim(to_char(avg(case item when 211 then value else null end),'99999999999990.99999'))) "SO2(mg/m3)"
from(select s.sitename,m.* from air_temphourdata m left join site s on m.sitecode=s.sitecode where m.SiteCode in ('34656-31102001','34656-31102006'))
group by sitename,Recordtime having to_char(Recordtime,'yyyymmddhhmmss')=MAX(to_char(Recordtime,'yyyymmddhhmmss'))
order by RecordTime desc ) n )p where p.序号 between 1 and 15 只查询出每个站点最大时间的那一条
![CSDN移动问答][1]

suannai0314
鹳狸媛 楼主的这个问题解决了么?下边的答案能解决问题么?如果可以麻烦点击答案旁的√采纳哦~如果没有也可以将自己的答案贴上然后进行采纳的。
接近 7 年之前 回复

1个回答

select p.* from
(select rownum as 序号 ,n.* from
(select sitename as 站点名称, max(RecordTime) as 记录时间 ,
decode(avg(case item when 211 then value else null end),0,'0.00000',
trim(to_char(avg(case item when 211 then value else null end),'99999999999990.99999'))) "SO2(mg/m3)" FROM
(select s.sitename,m.* from air_temphourdata m
left join site s on m.sitecode=s.sitecode
where m.SiteCode in ('34656-31102001','34656-31102006'))
group by sitename
) order by 站点名称 desc ) n )p
where p.序号 between 1 and 15

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐