zoukankan      html  css  js  c++  java
  • SAPHANA学习(16):SQL Function(P)

    /*

    107. PERCENT_RANK

    PERCENT_RANK() <window_specification>

    */

    SELECT "CLASS", "VAL", "OFFSET", 
           PERCENT_RANK() OVER (PARTITION BY "CLASS" ORDER BY "VAL" ASC) AS PER_RANK
           FROM "TEST_RANK" ORDER BY "VAL" DESC;

    /*

    108. PERCENTILE_CONT

    PERCENTILE_CONT( <constant_literal> )

           WITHIN GROUP ( ORDER BY <expression> [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ] ) <window_specification>

    NR = the number of rows in the window partition R*P = the specified percentile value**

           INDEX1 = floor( 1 + ( P * (NR - 1) ) )               

           INDEX2 = ceil( 1 + ( P * (NR - 1) ) )               

        COEF1 = INDEX2 - ( 1 + ( P * (NR - 1) ) )               

        COEF2 = INDEX1 - ( 1 + ( P * (NR - 1) ) )                               

    if INDEX1 == INDEX2                

    then returns (value at INDEX1)               

    else returns ( ( value at INDEX1 ) * COEF1 + ( value at INDEX2 ) * COEF2 )

    PERCENTILE_DISC( <constant_literal> )

           WITHIN GROUP ( ORDER BY <expression> [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ] ) <window_specification>

    */

    SELECT
      class,
      val, 
      PERCENTILE_CONT(0.125) WITHIN GROUP (ORDER BY val) OVER (PARTITION BY class) AS pc1, 
      PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY val) OVER (PARTITION BY class) AS pc2, 
      PERCENTILE_CONT(0.875) WITHIN GROUP (ORDER BY val) OVER (PARTITION BY class) AS pc3
     FROM TEST_RANK;
    
    SELECT
      class,
      val, 
      PERCENTILE_DISC(0.125) WITHIN GROUP (ORDER BY val) OVER (PARTITION BY class) AS pd1,
      PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY val) OVER (PARTITION BY class) AS pd2, 
      PERCENTILE_DISC(0.875) WITHIN GROUP (ORDER BY val) OVER (PARTITION BY class) AS pd3
     FROM TEST_RANK;
    

    /*

    109. PLAINTEXT

    PLAINTEXT(<column_name>)

    returns the plain text representation of a value in a column that has a full text index.

    */

    CREATE COLUMN TABLE TEST_PLAINTEXT (CONTENT BLOB);
    CREATE FULLTEXT INDEX I1 ON TEST_PLAINTEXT(CONTENT);
    INSERT INTO TEST_PLAINTEXT VALUES ('<somePDF>');
    SELECT PLAINTEXT(CONTENT),CONTENT FROM TEST_PLAINTEXT;

    /*

    110. POWER

    POWER(<base>, <exponent>)

    计算<base>的<exponent>次方

    */

    SELECT POWER (2, 10) FROM DUMMY;
    SELECT POWER (3, 3) FROM DUMMY;
  • 相关阅读:
    Mysql基本操作、C++Mysql简单应用、PythonMysql简单应用
    Mysql安装步骤
    MVC EF 移除建表时自动加上s的复数形式
    MVC autofac 属性注入
    layui table默认选中指定行
    js slice 假分页
    sql 根据身份证号码计算年龄
    pointer-events: none
    /Date(1555554794000)/ 转换为日期格式
    sql 查询字段如果为null 则返回0的写法
  • 原文地址:https://www.cnblogs.com/tangToms/p/13892843.html
Copyright © 2011-2022 走看看