码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2020-11-01 21:16:40      阅读:21      评论:0      收藏:0      [点我收藏+]

标签:int   --   set   specified   字符串   ber   assigned   bsp   font   

/*

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;

 

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

标签:int   --   set   specified   字符串   ber   assigned   bsp   font   

原文地址:https://www.cnblogs.com/tangToms/p/13868159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!