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]
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