加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – Crystal Reports需要按派生日期范围分组

发布时间:2020-12-12 16:27:06 所属栏目:MsSql教程 来源:网络整理
导读:长时间列表,第一次来电.我正在使用Crystal Reports 2010. 我有每日交易信息,如果交易量不变,我需要将它们组合在一起.这是数据的样子. 交易#BegDate EndDate卷 1 1/1/2012 1/2/2012 5001 1/2/2012 1/3/2012 5001 1/3/2012 1/4/2012 10001 1/4/2012 1/5/2012 75
长时间列表,第一次来电.我正在使用Crystal Reports 2010.

我有每日交易信息,如果交易量不变,我需要将它们组合在一起.这是数据的样子.

交易#BegDate EndDate卷

1        1/1/2012    1/2/2012    500
1        1/2/2012    1/3/2012    500
1        1/3/2012    1/4/2012    1000
1        1/4/2012    1/5/2012    750
1        1/5/2012    1/6/2012    750
1        1/6/2012    1/7/2012    500
1        1/7/2012    1/8/2012    500
1        1/8/2012    1/9/2012    500

我需要它看起来像这样.

Trade#DateRange Volume

1        1/1/2012 - 1/3/2012  500
1        1/3/2012 - 1/4/2012  1000
1        1/4/2012 - 1/6/2012  750
1        1/6/2012 - 1/9/2012  500

我需要按派生日期范围进行分组,但我不确定如何使用Crystal完成此操作.有任何想法吗??

解决方法

with w as (
 select 1 id,to_date('1/1/2012','mm/dd/yyyy') start_date,to_date('1/2/2012','mm/dd/yyyy') end_date,500 sales_volume from dual
 union all
 select 1,'mm/dd/yyyy'),to_date('1/3/2012',500 from dual
 union all
 select 1,to_date('1/4/2012',1000 from dual
 union all
 select 1,to_date('1/5/2012',750 from dual
 union all
 select 1,to_date('1/6/2012',to_date('1/7/2012',to_date('1/8/2012',to_date('1/9/2012',500 from dual      
 ),t as (select sales_volume,start_date,end_date,lag (sales_volume,1) over (order by start_date) prev_sales_volume
       from w
       order by start_date),u as (select *
       from t 
       where nvl(prev_sales_volume,-1) != sales_volume
       order by start_date)
select start_date,nvl(lead (start_date,1) over (order by start_date),(select max(end_date) from w))   end_date,sales_volume
from  u
order by start_date

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读