连续日期功能:SAP HANA

2020-09-19 02:31发布

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


我们正在尝试从表格中查找连续日期

预期输出如下图所示:

附加我们在SAP HANA中尝试过的查询

但是我们没有得到预期的输出,而是找到了我们使用SAP HANA SQL得到的附件。结束日期应该更改。(附件为输出图像)

创建列表" PS_CMP_TIME_ANALYTICS"。" Temp2"(
 " ID"整数,
 "期间"日期);

 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(4," 2010-04-03");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(5," 2010-04-07");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(2," 2010-04-10");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(3," 2010-04-15");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(6," 2010-04-16");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(7," 2010-04-17");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(3," 2010-04-22");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(4," 2010-04-24");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(7," 2010-04-30");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(2," 2010-05-01");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(5," 2010-05-02");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(3," 2010-05-03");


 SELECT MIN(" Period")AS BeginRange,
        MAX(" Period")AS EndRange
 来自(
 选择"句号",
     --DATEDIFF(D,ROW_NUMBER()OVER(ORDER BY" Period")," Period")AS DtRange
 将(ROW_NUMBER()OVER(ORDER BY" Period")as date)转换为xyz,

     days_between(to_date(cast(ROW_NUMBER()OVER(ORDER BY" Period")OVER as
 日期),'YYYY-MM-DD'),"句号")AS DtRange
 FROM" PS_CMP_TIME_ANALYTICS"。" Temp2")AS dt
 GROUP BY DtRange;


 

(7.7 kB)

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


我们正在尝试从表格中查找连续日期

预期输出如下图所示:

附加我们在SAP HANA中尝试过的查询

但是我们没有得到预期的输出,而是找到了我们使用SAP HANA SQL得到的附件。结束日期应该更改。(附件为输出图像)

创建列表" PS_CMP_TIME_ANALYTICS"。" Temp2"(
 " ID"整数,
 "期间"日期);

 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(4," 2010-04-03");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(5," 2010-04-07");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(2," 2010-04-10");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(3," 2010-04-15");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(6," 2010-04-16");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(7," 2010-04-17");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(3," 2010-04-22");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(4," 2010-04-24");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(7," 2010-04-30");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(2," 2010-05-01");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(5," 2010-05-02");
 插入" PS_CMP_TIME_ANALYTICS"。" Temp2"值(3," 2010-05-03");


 SELECT MIN(" Period")AS BeginRange,
        MAX(" Period")AS EndRange
 来自(
 选择"句号",
     --DATEDIFF(D,ROW_NUMBER()OVER(ORDER BY" Period")," Period")AS DtRange
 将(ROW_NUMBER()OVER(ORDER BY" Period")as date)转换为xyz,

     days_between(to_date(cast(ROW_NUMBER()OVER(ORDER BY" Period")OVER as
 日期),'YYYY-MM-DD'),"句号")AS DtRange
 FROM" PS_CMP_TIME_ANALYTICS"。" Temp2")AS dt
 GROUP BY DtRange;


 

(7.7 kB)
付费偷看设置
发送
1条回答
Violet凡
1楼-- · 2020-09-19 03:07

嗨,

您可以使用以下代码

将SELECT MIN(" Period")设置为" Start_Date",将MAX(" Period")设置为" End_Date",(days_between(Min(" Period"),Max(" Period"))+ 1)作为" Days"
 --days_between(to_date(cast(ROW_NUMBER()OVER(ORDER BY" Date")as Date),'YYYY-MM-DD')," Date")AS pqr
  从
   (选择" Period",add_days(" Period",-ROW_NUMBER()OVER(ORDER BY" Period")))
   来自" PS_CMP_TIME_ANALYTICS"。" Temp2")
 
   分组依据
 

致谢

Raja Y

一周热门 更多>