• SAPHANA学习(3):SQL Function(B)


    /*

    21.BINNING Function

    Partitions an input set into disjoint subsets by assigning a bin number to each row.

    BINNING( <binning_param> => <expression> [ {, <binning_parameter> => <expression> } ... ] ) <window_specification>

    <binning_param> ::= VALUE | BIN_COUNT | BIN_WIDTH | TILE_COUNT | STDDEV_COUNT

    VALUE is always required.

    It specifies the column that binning is applied to.

    When BIN_WIDTH is used, the input column must have a numeric data type.

    BIN_COUNT specifies the number of equal-width bins.

    BIN_WIDTH specifies the width of the bins.

    TILE_COUNT specifies the number of bins with equal number of records.

    STDDEV_COUNT specifies the number of standard deviations left and right from the mean.

    The appropriate binning method is selected based on the parameter specified – exactly one of the last four parameters must be non-NULL.

    The value assigned to binning method parameter must be an integer expression.

    */

    CREATE ROW TABLE weather (station INT, ts DATE, temperature FLOAT);
    INSERT INTO weather VALUES(1, '2014-01-01', 0);
    INSERT INTO weather VALUES(1, '2014-01-02', 3);
    INSERT INTO weather VALUES(1, '2014-01-03', 4.5);
    INSERT INTO weather VALUES(1, '2014-01-04', 6);
    INSERT INTO weather VALUES(1, '2014-01-05', 6.3);
    INSERT INTO weather VALUES(1, '2014-01-06', 5.9);
    INSERT INTO weather VALUES(1, '2015-01-01', 1);
    INSERT INTO weather VALUES(1, '2015-01-02', 3.4);
    INSERT INTO weather VALUES(1, '2015-01-03', 5);
    INSERT INTO weather VALUES(1, '2015-01-04', 6.7);
    INSERT INTO weather VALUES(1, '2015-01-05', 4.6);
    INSERT INTO weather VALUES(1, '2015-01-06', 6.9);
    
    --OVER子句不能指定 <window_order_by_clause>,也不能指定任何窗口框架,因为binning函数在整个分区上工作。
    SELECT *,
           BINNING(
           VALUE => temperature,
           BIN_COUNT => 4)
           OVER () AS bin_num FROM weather;

    /*

    22.BINTOHEX Function

    BINTOHEX(<expression>)

    将二进制值转换为VARCHAR数据类型十六进制值。如果输入值不是二进制值,则首先将其转换为二进制值。

    23.BINTONHEX Function

    BINTONHEX(<expression>)

    将二进制值转换为NVARCHAR数据类型十六进制值。如果输入值不是二进制值,则首先将其转换为二进制值。

    24.BINTOSTR

    BINTOSTR(<varbinary_string>)

    Converts a VARBINARY string <varbinary_string> to a character string with CESU-8 encoding.

    */

    SELECT BINTOHEX('AB') FROM DUMMY;
    SELECT BINTONHEX('AB') FROM DUMMY;
    SELECT BINTOSTR ('416E74') FROM DUMMY;
    

    /*

    25.BITAND Function

    BITAND(<value1>, <value2>)

    按位与操作

    <value1>,<value2>必须是非负整数,VARBINARY类型

    BITAND会将输入字符串类型值转换为BIGINT,BITOR,BITXOR,BITNOT Function转换为INT

    26.BITCOUNT Function

    BITCOUNT(<expression>)

    <expression>必须是整数或VARBINARY类型

    返回整型数据,位数

    27.BITNOT Function

    BITNOT(<expression>)

    按位执行非操作

    28.BITOR Function

    BITOR(<expression1>, <expression2>)

    <expression1>,<expression2>必须非负整数或VARBINARY类型

    按位执行或操作

    29.BITXOR Function

    BITXOR(<expression1>, <expression2>)

    按位执行异或操作

    <expression1>, <expression2>必须是非负整数或VARBINARY类型

    30.BITSET Function

    BITSET(<target_num>, <start_bit>, <num_to_set>)

    Sets a specific number of bits to 1 in a target number from a specified 1-based index position.

    <target_num> ::= <string_literal>

    The VARBINARY number where the bits are to be set.

    <start_bit> ::= <unsigned_integer>

    A 1-based index position where the first bit is to be set.

    <num_to_set> ::= <unsigned_integer>

    The number of bits to be set in the target number.

    31.BITUNSET Function

    BITUNSET(<target_num>, <start_bit>, <num_to_unset>)

    Sets a specified number of bits to 0 in a target number from a specified 1-based index position.

    */

    SELECT BITAND (255, 123)  FROM DUMMY;
    SELECT BITCOUNT (255) FROM DUMMY;
    SELECT BITNOT (255) FROM DUMMY;
    SELECT BITOR (255, 123) FROM DUMMY;
    
    --255=>1111 1111   123=>0111 1011,进行异或运算 1000 0100
    SELECT BITXOR (255, 123) FROM DUMMY;
    SELECT BITSET ('1111', 1, 3) FROM DUMMY;
    SELECT BITUNSET ('ffff', 1, 3) FROM DUMMY;
  • 相关阅读:
    199. 二叉树的右视图
    二叉树前、中、后、层次、遍历的非递归法
    奇思妙想
    917. 仅仅反转字母【双指针】
    JVM性能监控与故障处理工具
    Java线程池使用和常用参数(待续)
    MySQL常用知识
    手写常用算法
    LightOj 1170
    逆元总结
  • 原文地址:https://www.cnblogs.com/tangToms/p/13868159.html
Copyright © 2020-2023  润新知