滞后函数问题(db2)

时间:2015-11-04 02:15:55

标签: db2

我有一个包含以下列的表:

userid  Designation load_dt     audit_time  type  
A       Engg        3/11/2015   22/06/2015   R        
A       Engg        4/11/2015   03/07/2015   D            
A       Engg        31/12/9999  4/10/2015    R    
A       doc         31/12/9999  22/06/2015   R    

我正在尝试通过在userid和指定的基础上跟踪audit_time的变化来创建输出。对于第一行,开始日期将是01-01-1900,如果不存在其他记录,则结束日期将是12-31-9999。对于userid = A,由于更改发生在2015年7月3日,因此第一条记录的开始日期为01/01/1900,并于2015年7月3日结束。第二条记录的开始日期为2015年7月3日,并一直有效至2015年4月10日。第三次更改从2015年10月4日开始,并有未来结束日期。

userid  Designation load_dt     audit_time  type  start_date   end_date

A       Engg        3/11/2015   22/06/2015  R     01/01/1900   03/07/2015       
A       Engg        4/11/2015   03/07/2015  D   **03/07/2015   4/10/2015            
A       Engg        31/12/9999  4/10/2015    R  **4/10/2015    31/12/9999   
A       doc         31/12/9999  22/06/2015   R    01/01/1900   31/12/9999

我使用了以下查询:

select userid, designation, LOAD_DT, AUDIT_TIME, TYPE   
, coalesce(lag(AUDIT_TIME ) over (partition by userid, designation order by AUDIT_TIME),'1900-01-01') start   
, coalesce(lead(AUDIT_TIME ) over (partition by userid, designation order by AUDIT_TIME),'9999-12-31') enddt   
from DUMMY1;

我得到以下结果:

userid  Designation load_dt     audit_time  type  start_date   end_date   
A       Engg        3/11/2015   22/06/2015   R    01/01/1900   03/07/2015   
A       Engg        4/11/2015   03/07/2015   D  **22/06/2015   4/10/2015        
A       Engg        31/12/9999  4/10/2015    R  **03/07/2015   31/12/9999   
A       doc         31/12/9999  22/06/2015   R    01/01/1900   31/12/9999     

我希望我能够正确解释我的问题。

1 个答案:

答案 0 :(得分:0)

我只需调整滞后计算即可解决问题:

2015-11-04 19:48:56.985 ERROR 138300 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration]; nested exception is java.lang.IllegalStateException: Annotation @EnableDiscoveryClient found, but there are no implementations.  Did you forget to include a starter?
        at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:437)
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:183)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:306)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
        at com.my.example.EurekaApplication.main(EurekaApplication.java:20)
Caused by: java.lang.IllegalStateException: Annotation @EnableDiscoveryClient found, but there are no implementations.  Did you forget to include a starter?
        at org.springframework.cloud.util.SpringFactoryImportSelector.selectImports(SpringFactoryImportSelector.java:75)
        at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:429)
        ... 13 common frames omitted