oracle时间分析函数大全,分析函数,千万级表,取最大时间的问题,求助

本帖最后由 IT渔夫 于 2016-3-1 09:44 编辑

eq_guidcycle_timecurrent_valuelately_value

A2016年2月29日10090

A2016年3月1日100

A2016年3月2日

A2016年3月3日

A2016年3月4日

A2016年3月5日

A2016年3月6日

A2016年3月7日150

A2016年3月8日152150

A2016年3月9日160152

A2016年3月10日160

A2016年3月11日

B2016年2月29日8785

B2016年3月1日9387

B2016年3月2日9593

B2016年3月3日95

B2016年3月4日

B2016年3月5日

B2016年3月6日

B2016年3月7日105

B2016年3月8日108105

B2016年3月9日117108

B2016年3月10日117

B2016年3月11日

C2016年2月29日

C2016年3月1日

C2016年3月2日

C2016年3月3日100

C2016年3月4日

C2016年3月5日

C2016年3月6日106

C2016年3月7日108106

C2016年3月8日108

C2016年3月9日

C2016年3月10日

C2016年3月11日

以上表中,数据量有上千万。我需要根据eq_guid取最大cycle_time的,前提是同一eq_guid下,current_value和lately_value不为空,且之前的cycle_time下的current_value和lately_value都不为空

以上数据中,A取的数据是2016年2月29日,B取的是2016年3月2日(B的3月8日和3月9日的的current_value和lately_value都不为空,但是3月3日、3月4日等的current_value和lately_value为空,因此只能取到3月2日,B的3月2日之前的current_value和lately_value都是不为空),C的话,取的是空(C的3月7日的current_value和lately_value不为空,但是之前2月29日、3月1日等都为空,因此C取不到任何数据)

with t as

(

select 'A'  eq_guid, to_date('2016-2-29','yyyy-mm-dd')  cycle_time,  100 current_value,  90  lately_value from dual union all

select 'A'  eq_guid, to_date('2016-3-1' ,'yyyy-mm-dd') cycle_time,  null current_value,  100 lately_value from dual union all

select 'A'  eq_guid, to_date('2016-3-4' ,'yyyy-mm-dd') cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'A'  eq_guid, to_date('2016-3-5' ,'yyyy-mm-dd') cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'A'  eq_guid, to_date('2016-3-6' ,'yyyy-mm-dd') cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'A'  eq_guid, to_date('2016-3-7' ,'yyyy-mm-dd') cycle_time,  150 current_value,  null  lately_value   from dual union all

select 'A'  eq_guid, to_date('2016-3-8' ,'yyyy-mm-dd') cycle_time,  152 current_value,  150 lately_value from dual union all

select 'A'  eq_guid, to_date('2016-3-9' ,'yyyy-mm-dd') cycle_time,  160 current_value,  152 lately_value from dual union all

select 'A'  eq_guid, to_date('2016-3-10','yyyy-mm-dd')  cycle_time,  null  current_value,  160 lately_value   from dual union all

select 'A'  eq_guid, to_date('2016-3-11','yyyy-mm-dd')  cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'B'  eq_guid, to_date('2016-2-29','yyyy-mm-dd')  cycle_time,  87  current_value,  85  lately_value   from dual union all

select 'B'  eq_guid, to_date('2016-3-1' ,'yyyy-mm-dd') cycle_time,  93 current_value,  87  lately_value   from dual union all

select 'B'  eq_guid, to_date('2016-3-2' ,'yyyy-mm-dd') cycle_time,  95 current_value,  93  lately_value   from dual union all

select 'B'  eq_guid, to_date('2016-3-3' ,'yyyy-mm-dd') cycle_time,  null  current_value,  95  lately_value   from dual union all

select 'B'  eq_guid, to_date('2016-3-8' ,'yyyy-mm-dd') cycle_time,  108 current_value,  105 lately_value from dual union all

select 'B'  eq_guid, to_date('2016-3-9' ,'yyyy-mm-dd') cycle_time,  117 current_value,  108 lately_value from dual union all

select 'B'  eq_guid, to_date('2016-3-10','yyyy-mm-dd')  cycle_time,  null  current_value,  117 lately_value   from dual union all

select 'B'  eq_guid, to_date('2016-3-11','yyyy-mm-dd')  cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'C'  eq_guid, to_date('2016-2-29','yyyy-mm-dd')  cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'C'  eq_guid, to_date('2016-3-1' ,'yyyy-mm-dd') cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'C'  eq_guid, to_date('2016-3-2' ,'yyyy-mm-dd') cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'C'  eq_guid, to_date('2016-3-3' ,'yyyy-mm-dd') cycle_time,  100 current_value,  null  lately_value   from dual union all

select 'C'  eq_guid, to_date('2016-3-4' ,'yyyy-mm-dd') cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'C'  eq_guid, to_date('2016-3-5' ,'yyyy-mm-dd') cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'C'  eq_guid, to_date('2016-3-6' ,'yyyy-mm-dd') cycle_time,  106 current_value,  null  lately_value   from dual union all

select 'C'  eq_guid, to_date('2016-3-7' ,'yyyy-mm-dd') cycle_time,  108 current_value,  106 lately_value from dual union all

select 'C'  eq_guid, to_date('2016-3-8' ,'yyyy-mm-dd') cycle_time,  null  current_value,  108 lately_value   from dual union all

select 'C'  eq_guid, to_date('2016-3-9' ,'yyyy-mm-dd') cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'C'  eq_guid, to_date('2016-3-10','yyyy-mm-dd')  cycle_time,  null  current_value,  null  lately_value  from dual union all

select 'C'  eq_guid, to_date('2016-3-11','yyyy-mm-dd')  cycle_time,  null  current_value,  null  lately_value  from dual

)

select  * from t;以上示例数据中,A取到2月29日那一条,B的结果是3月2日那一条,C无法取到任何数据。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值