【问题标题】:sap hana sql dates aggregationsap hana sql 日期聚合
【发布时间】:2017-02-03 05:22:05
【问题描述】:

我为 sap hana 编写的查询存在问题。

基本上有两张桌子。

第一个表是一个日期表,其中包含日历中每一天的日期。第二个表是一个结果表,其中包含一个客户参考号和每个客户参考号的开始日期和结束日期。在这个客户参考表中,我有大约 400 万条记录。因此,基本上在查询的内部部分,我将从 01012011 开始每天获得 400 万条记录。必须有一种简单的方法来汇总结果。我尝试了一个内部选择查询,但似乎 hana 存在性能问题。

我已经编写了这样的代码,但这不是最佳的。

   select date_sql, count(*) as count
           from (
                select date_sql 
                    from  tbl_ref_cal_link tbl_date                     
                       where date_sql between '2011-01-01' and add_days (to_date(current_date, 'YYYY-MM-DD'), -1)                       
   )tbl_date
            Left join #cust_ref_table M1
                 On tbl_date.date_sql between m1.startdate and m2.enddate)z

感谢任何人的帮助或建议。

【问题讨论】:

    标签: sql hana


    【解决方案1】:

    您可以在此处使用 Group By 并且您需要将 WHERE 子句中的 m2 更改为 m1,如下面的 SQLScript 代码所示

    select
        date_sql, count(m1.CustomerId) as count
    from (
    -- dates table here
    ) tbl_date
    Left join cust_ref_table m1 On tbl_date.date_sql between m1.startdate and m1.enddate 
    group by date_sql
    

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 1970-01-01
      • 2022-01-04
      • 2018-05-31
      相关资源
      最近更新 更多