表字段有:站号、日期、气温
主键为站点和日期 站号 日期 气温
1 2009-1-1 5
2 2009-1-1 13
3 2009-1-1 8
4 2009-1-1 11
1 2009-1-2 6
2 2009-1-2 8
3 2009-1-2 5
4 2009-1-2 12 要查询某段时期内指定站号的最高气温,以及出现日期,比如查询站号1和站号2在2009年1月1号到1月2号这段时期内最高气温以及出现的日期,查询结果如下:站号 最高气温 出现日期
1 6 2009-1-2
2 13 2009-1-1请问这个sql语句应该怎么写?
主键为站点和日期 站号 日期 气温
1 2009-1-1 5
2 2009-1-1 13
3 2009-1-1 8
4 2009-1-1 11
1 2009-1-2 6
2 2009-1-2 8
3 2009-1-2 5
4 2009-1-2 12 要查询某段时期内指定站号的最高气温,以及出现日期,比如查询站号1和站号2在2009年1月1号到1月2号这段时期内最高气温以及出现的日期,查询结果如下:站号 最高气温 出现日期
1 6 2009-1-2
2 13 2009-1-1请问这个sql语句应该怎么写?
from tb a
inner join (select 站号,max(气温) 气温 from tb group by 站号)b
on a.站号=b.站号 and a.气温=b.气温
from tb a
inner join (select 站号,max(气温) 气温 from tb group by 站号)b
on a.站号=b.站号 and a.气温=b.气温
where (a.站号=1 or a.站号=2)
and to_char(a.日期,'YYYY-MM-DD' between '2009-01-01' and '2009-01-02'
from (
select 站号, 日期, 气温, row_number() over(partition by 站号 order by 气温 desc) rn
from mytab
where 日期 between to_date('20090101','YYYYMMDD') and to_date('20090102','yyyymmdd')
) where rn = 1
但我这样写时间的条件就写了两次,写一次就查不出了,不知道有没有改进方法?
select a.*
from
(select * from Tab where
Vdate>=to_date('2005-8-1','yyyy-mm-dd') and Vdate<=to_date('2005-8-31','yyyy-mm-dd')) a,
(select IIIII,max(气温) 最高气温 from Tab where
Vdate>=to_date('2005-8-1','yyyy-mm-dd') and Vdate<=to_date('2005-8-31','yyyy-mm-dd') and
(站号=1 or 站号=2) group by 站号) b
where a.站号=b.站号 and a.气温=b.气温;
请问rn = 1代表什么意思?
还有“partition by ”这句话都是啥意思?谢谢:)
partition by 是分区或分组
分析函数跟sum,avg之类函数类似,google一下