/*
81.LAG
LAG( <expression> [, <offset> [, <default_expr> ] ] ) <window_specification>
<offset>非负整数,默认1;
<default_expr>,如果超过记录,返回<default_expr>值;如果没设置,返回null;
返回当前行之前偏移行的值。
LEAD( <expression> [, <offset> [, <default_expr> ] ] ) <window_specification>
返回当前行之后的行偏移量。
*/
SELECT TS_ID,VALUE1,VALUE2, LEAD(VALUE1) OVER (PARTITION BY TS_ID ORDER BY VALUE1) AS lead, LEAD(VALUE1,VALUE2,-VALUE1) OVER (PARTITION BY TS_ID ORDER BY VALUE1) AS lead2, LAG(VALUE1) OVER (PARTITION BY TS_ID ORDER BY VALUE1) AS lag, LAG(VALUE1,VALUE2,-VALUE1) OVER (PARTITION BY TS_ID ORDER BY VALUE1) AS lag2 FROM CORRELATIONTABLE3;
/*
82.LANGUAGE(<column_name>)
*/
CREATE COLUMN TABLE TEST_LANGUAGE (CONTENT TEXT FAST PREPROCESS OFF LANGUAGE DETECTION('EN','DE')); INSERT INTO TEST_LANGUAGE VALUES('This is a very short example.'); INSERT INTO TEST_LANGUAGE VALUES('Dies ist ein ganz kurzes Beispiel.'); SELECT LANGUAGE(CONTENT),CONTENT FROM TEST_LANGUAGE;
/*
83.LAST_DAY(<date>)
返回包含指定日期月份最后一天
*/
SELECT LAST_DAY(TO_DATE('2010-01-04', 'YYYY-MM-DD')) FROM DUMMY;
/*
84.LAST_VALUE
Aggregate function:
LAST_VALUE( <expression> <order_by_clause> )
Window function:
LAST_VALUE( <expression> <order_by_clause> ) <window_specification>
<order_by_clause> ::= ORDER BY <order_by_expression> [, <order_by_expression> [,...] ]
<order_by_expression> ::= <column_name> [ <collate_clause> ] [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ]
| <column_position> [ <collate_clause> ] [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ]
<collate_clause> ::= COLLATE <collation_name>
*/
SELECT LAST_VALUE ("VALUE" ORDER BY TS_ID) FROM CORRELATIONTABLE;
/*
85.LCASE(<string>)
将<string>转换小写,和LOWER Function功能相似
*/
SELECT LCASE ('TesT') FROM DUMMY;
/*
86.LEAST(<argument_1> [, <argument_2>]...)
返回较小值
*/
SELECT LEAST('aa', 'ab', 'ba', 'bb') FROM DUMMY;
/*
87.LEFT
LEFT(<string>, <number>)
<string>操作字符串
<number>返回字符串长度
返回前<number>个字符串,如果<number>小于1,返回空;
LENGTH(<string>)
返回<string>字符串长度
*/
SELECT LEFT ('Hello', 3) FROM DUMMY; SELECT LEFT ('Hello', 10) FROM DUMMY; SELECT LENGTH ('length in char') FROM DUMMY;
/*
88.LINEAR_APPROX
LINEAR_APPROX(<expression> [, <ModeArgument> [, <Value1Argument> [,
<Value2Argument>]]]) OVER ({ SERIES TABLE <table_schema> [<window_partition_by_clause>]
[<window_order_by_clause>] | SERIES(...) [<window_partition_by_clause>]
[<window_order_by_clause>] | [<window_partition_by_clause>] <window_order_by_clause>})
<expression> ::= <identifier>
在一个序列中插入值,替换null值
<ModeArgument> ::= EXTRAPOLATION_NONE
| EXTRAPOLATION_LINEAR
| EXTRAPOLATION_CONSTANT
EXTRAPOLATION_NONE:默认模式,此模式不会处理前置或后置null值,只处理中间null值,不需要指定<Value1Argument><Value2Argument>
EXTRAPOLATION_LINEAR:线性外推,<Value1Argument>最小值,<Value2Argument>最大值,
当前置,后置null值推导过程中值不在<Value1Argumen><Value2Argument>范围,替换成<Value1Argument><Value2Argument>
EXTRAPOLATION_CONSTANT:线性外推,前置null值替换为<Value1Argument>,后置null值替换为<Value2Argument>
NON-EQUIDISTANT :An error occurs if the series is non-equidistant.
MISSING ELEMENTS ALLOWED :When specified, there must be exactly one ORDER BY column that is compatible with the type of the series period column and the INCREMENT BY value.
PARTITION BY :If not specified, the SERIES KEY property of the SERIES syntax is used to construct the default PARTITION BY.
ORDER BY :If not specified, the first PERIOD column is added as an ORDER BY.
*/
CREATE COLUMN TABLE "SparseApproxTable" (ts_id VARCHAR(20), date DAYDATE, val DOUBLE); INSERT INTO "SparseApproxTable" VALUES('A','2013-11-01', null); INSERT INTO "SparseApproxTable" VALUES('A','2014-01-01', null); INSERT INTO "SparseApproxTable" VALUES('A','2014-02-05', 2); INSERT INTO "SparseApproxTable" VALUES('A','2014-03-07', null); INSERT INTO "SparseApproxTable" VALUES('A','2014-05-01', 5); INSERT INTO "SparseApproxTable" VALUES('A','2014-07-27', 7); INSERT INTO "SparseApproxTable" VALUES('A','2014-12-07', null); INSERT INTO "SparseApproxTable" VALUES('A','2015-02-07', null); SELECT LINEAR_APPROX(val, 'EXTRAPOLATION_LINEAR') OVER ( SERIES ( SERIES KEY(ts_id) EQUIDISTANT INCREMENT BY INTERVAL 1 MONTH MISSING ELEMENTS ALLOWED PERIOD FOR SERIES(date) ) PARTITION BY ts_id) AS approximated_value FROM "SparseApproxTable"; CREATE COLUMN TABLE "InterpolationTable" (TS_ID VARCHAR(20), date DAYDATE, val DOUBLE); INSERT INTO "InterpolationTable" VALUES('A','2013-09-30', 1); INSERT INTO "InterpolationTable" VALUES('A','2013-10-01', 2); INSERT INTO "InterpolationTable" VALUES('A','2013-10-02', null); INSERT INTO "InterpolationTable" VALUES('A','2013-10-03', 10); SELECT LINEAR_APPROX (val, 'EXTRAPOLATION_LINEAR') OVER (PARTITION BY TS_ID ORDER BY date) AS LINEAR_APPROX FROM "InterpolationTable";
/*
89.LN
LN(<number>)
返回e为底自然对数
LOG(<base>, <number>)
返回<base>为底,值为<number>的自然对数值
<base>大于1的正数,<number>任意正数
*/
SELECT LN(1) FROM DUMMY; SELECT LOG (2, 8) FROM DUMMY;
/*
90.LOCALTOUTC
LOCALTOUTC (<time> [, <timezone> [, <timezone_dataset>]])
将本地时间转换为UTC时间
<time> ::= <timestamp>
<timezone> ::= <string_literal>
<timezone_dataset> ::= { sap | platform }
*/
SELECT LOCALTOUTC (TO_TIMESTAMP('2012-01-01 01:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'EST') FROM DUMMY; SELECT LOCALTOUTC (TO_TIMESTAMP('2012-01-01 01:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'EST', 'sap') FROM DUMMY;
/*
91.LOCATE
LOCATE( <haystack>, <needle>, [<start_position>] , [ <occurrences> ] )
返回<needle>子字符串在<haystack>中位置,<start_position>匹配开始位置,<occurences>返回第几次匹配结果;
如果没有找到,<occurrences>小于1,返回0;
如果<needle>,<haystack><occurences>为null,返回null;
<start_position>为正数,从左到右匹配;
<start_position>为负数,从右到左匹配;
LOCATE_REGEXPR( [ <regex_position_start_or_after> ] <pattern>
[ FLAG <flag> ]
IN <regex_subject_string>
[ FROM <start_position> ]
[ OCCURRENCE <regex_occurrence> ]
[ GROUP <regex_capture_group> ]
*/
--返回从右到左第一个A SELECT LOCATE('AACAB', 'A', -1) FROM "DUMMY"; SELECT LOCATE ('length in char','',2) FROM DUMMY; SELECT LOCATE ('length in char', 'zin') "locate" FROM DUMMY;
/*
92.LOWER(<string>)
将字符串转换小写
*/
SELECT LOWER ('AnT') FROM DUMMY;
/*
93.LPAD
LPAD(<string>, <number> [, <pattern>])
在<string>字符串左边填充<pattern>达到<number>长度
LTRIM(<string> [, <remove_set>])
去前导0
*/
SELECT LPAD ('end', 15, '12345') FROM DUMMY; --当<number>小于<string>长度,截取左边<number>长度字符串 SELECT LPAD ('end', 2, '12345') FROM DUMMY; SELECT LTRIM(' end') FROM DUMMY; --设置<remove_set>,去掉所有前置字符,a,b SELECT LTRIM ('babababAabend','ab') FROM DUMMY;