• SAP HANA grouping sets 、rollup、cube、limit 实践


    create column table .t1 ( id int primary key, customer varchar(5), year int, product
    varchar(5), sales int );
    insert into t1 values(1, 'C1', 2009, 'P1', 100);
    insert into t1 values(2, 'C1', 2009, 'P2', 200);
    insert into t1 values(3, 'C1', 2010, 'P1', 50);
    insert into t1 values(4, 'C1', 2010, 'P2', 150);
    insert into t1 values(5, 'C2', 2009, 'P1', 200);
    insert into t1 values(6, 'C2', 2009, 'P2', 300);
    insert into t1 values(7, 'C2', 2010, 'P1', 100);
    insert into t1 values(8, 'C2', 2010, 'P2', 150);

    select customer, year, product, sum(sales) from ""."T1" 
    group by GROUPING SETS ((customer, year),(customer, product));

    ROLLUP
    select customer, year, sum(sales) from t1 group by ROLLUP(customer, year)

    select customer, year, sum(sales) from t1 group by CUBE(customer, year);
    

    select customer, year, sum(sales) from t1 group by CUBE best 1 (customer, year);
    
    select customer, year, sum(sales) from t1 group by CUBE best 2 (customer, year);

    select customer, year, sum(sales) from t1 group by CUBE best 3 (customer, year);

    
    

    select customer, year, product, sum(sales) from "ZHAIMING"."T1"
    group by GROUPING SETS LIMIT 2 ((customer, year),(customer, product))

     

    select customer, year, product, sum(sales)
    from t1 group by grouping sets LIMIT 2 WITH SUBTOTAL
    ( (customer, year), (product) );

    select customer, year, sum(sales) from t1 group by CUBE limit 1 with balance (customer, year)

    with total
    select customer, year, product, sum(sales)
    from t1 group by grouping sets LIMIT 2 WITH TOTAL
    ( (customer, year), (product) )

    select customer, year, product, sum(sales), text_filter(customer),
    text_filter(product) from t1 group by grouping sets TEXT_FILTER ‘*2’
    ( (customer, year), (product) )

    fill up
    select customer, year, product, sum(sales),
    text_filter(customer), text_filter(product)
    from t1 group by grouping sets TEXT_FILTER ‘*2’ FILL UP
    ( (customer, year), (product) )
    与text_filter对照看,这里返回的结果集里没有过滤掉不符合条件的。

     这是hana版本不行吗,

    select customer, year, product, sum(sales) from "T1" 
    group by GROUPING SETS LIMIT 2 ((customer, year),(customer, product));
    
    select customer, year, sum(sales) from T1  group by ROLLUP(customer, year);
    
    select customer, year, sum(sales) from t1 group by CUBE  (customer, year);
    
    
    select customer, year, sum(sales) from t1 group by CUBE best 1 (customer, year);
    
    select customer, year, sum(sales) from t1 group by CUBE best 2 (customer, year);
    
    select customer, year, sum(sales) from t1 group by CUBE best 3 (customer, year);
    
    
    select customer, year, product, sum(sales) from t1 group by grouping sets LIMIT 2
    ( (customer, year), (product) );
     
     
    select customer, year, product, sum(sales)
    from t1 group by grouping sets LIMIT 2 WITH SUBTOTAL
    ( (customer, year), (product) );
    
    select customer, year, sum(sales) from t1 group by CUBE  with balance (customer, year)
    
    
    select customer, year, product, sum(sales)
    from t1 group by grouping sets  WITH TOTAL
    ( (customer, year), (product) )
    
    select customer, year, product, sum(sales), text_filter(customer),
    text_filter(product) from t1 group by grouping sets TEXT_FILTER '*2'
    ( (customer, year), (product) )
    
    
    select customer, year, product, sum(sales),
    text_filter(customer), text_filter(product)
    from t1 group by grouping sets TEXT_FILTER '*2' FILL UP
    ( (customer, year), (product) )
    
    
    select customer, year, product, sum(sales),text_filter(customer), text_filter(product)
    from t1 group by grouping sets TEXT_FILTER '*2' FILL UP SORT MATCHS TO TOP ( (customer, year), (product) )

    参考:https://my.oschina.net/corleone/blog/131576

  • 相关阅读:
    CCF-CSP201512-3 画图
    CCF-CSP201512-2 消除类游戏
    CCF-CSP201606-4 游戏(BFS)
    CCF-CSP201604-2 俄罗斯方块
    HDU1035 Robot Motion(dfs)
    Java Srting之Calendar日历类(五)——Calendar中计算时间的方法add()
    java如何获取当前日期和时间
    double 类型怎样不用科学计数法表示并且使用Java正则表达式去掉Double类型的数据后面多余的0
    @SpringBootApplication(exclude={DataSourceAutoConfiguration.class})注解作用
    java.util.Date.toString()方法实例
  • 原文地址:https://www.cnblogs.com/mingdashu/p/15560498.html
Copyright © 2020-2023  润新知