1. 程式人生 > >hvie常用函式整理(未完)

hvie常用函式整理(未完)


19	abs
20	acos
21	add_months     add_months(start_date, num_months) - Returns the date that is num_months after start_date.
		>> SELECT add_months(to_date('2019-01-31'),1)  =>  2019-02-28
22	and  a1 and a2 and ... and an - Logical and
		>> SELECT true and true   => true
		>> SELECT true and false   => false
23	array 			array(n0, n1...) - Creates an array with the given elements 
		>> SELECT array(1,2,3) as arr   => [1,2,3] 返回一個數組
24	array_contains  array_contains(array, value) - Returns TRUE if the array contains value
		>> SELECT array_contains(array(1,2,3),21)  =>false
		>> SELECT array_contains(array(1,2,3),2)   =>true
25	ascii	ascii(str) - returns the numeric value of the first character of str
		>>  SELECT ascii('1')  => 49  
		>>  SELECT ascii('你')  => -28
26	asin
27	assert_true    assert_true(condition) - Throw an exception if 'condition' is not true
		>>  SELECT assert_true(true)	=> NULL
		>>  SELECT assert_true(FALSE)  	=> 拋異常
28	atan
29	avg
30	base64
31	between

32	bin   	bin(n) - returns n in binary
		>>   SELECT BIN(99)   =>1100011

33	bround  bround(x[, d]) - round x to d decimal places using HALF_EVEN rounding mode
		>> 不清楚和round的區別
34	case   CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END - When a = b, returns c; when a = d, return e; else return f

35	cbrt  	cbrt(double) - Returns the cube root of a double value.  返回一個double型別的立方根,當然也可以是整形的立方根
		>> SELECT cbrt(27.09)   => 3.003329636473136
		>> SELECT cbrt(27)   	=> 3
36	ceil  	ceil(x) - Find the smallest integer not smaller than x  找到一個大於x的最小整形,向上(大)取整數
 		>> SELECT ceil(28.99)	=>   29
		>> SELECT ceil(-28.99)	=>   -28
37	ceiling  ceiling(x) - Find the smallest integer not smaller than x
38	chr      chr(str) - convert n where n : [0, 256) into the ascii equivalent as a varchar.If n is less than 0 return the empty string. If n > 256, return chr(n % 256).
		>>  返回引數的ascii碼值 和 ascii整好相反
		>>  SELECT chr("49") <==> 1  <==> SELECT ascii('1')
39	coalesce  coalesce(a1, a2, ...) - Returns the first non-null argument  返回第一個非空值
		>> SELECT coalesce(null,"A","B")			=> "A"
		>> SELECT coalesce(array(null,"A","B"))		=> array(null,"A","B")

40	collect_list	collect_list(x) - Returns a list of objects with duplicates
41	collect_set     collect_set(x) - Returns a set of objects with duplicate elements eliminated
 
		 	t2.id	t2.catalog
			1			AA
			1			BB
			2			CC
			2			DD
		>> select id,concat('["',concat_ws('","',collect_set(catalog)),'"]') from t2 group by id
 
 			id			_c1
			1		["AA","BB"]
			2		["CC","DD"]


42	compute_stats  compute_stats(x) - Returns the statistical summary of a set of primitive type values


43	concat      concat(str1, str2, ... strN) - returns the concatenation of str1, str2, ... strN or concat(bin1, bin2, ... binN) - returns the concatenation of bytes in binary data  bin1, bin2, ... binN
		>> SELECT concat('-','A','Z')  									   => -AZ
44	concat_ws      concat_ws(separator, [string | array(string)]+) - returns the concatenation of the strings separated by the separator
		>> SELECT concat_ws('-',array("A","B","C"))						   =>A-B-C
		>> SELECT concat_ws('-',array("A","B","C"),array("X","Y","Z"))     =>A-B-C-X-Y-Z
		>> SELECT concat_ws('-','A','Z')    							   =>A-Z

45	context_ngrams		context_ngrams(expr, array<string1, string2, ...>, k, pf) estimates the top-k most frequent n-grams that fit into the specified context. The second parameter specifies a string of words that specify the positions of the n-gram elements, with a null value standing in for a 'blank' that must be filled by an n-gram element.

sencenses	sentences(str,lang,country) - Splits str into arrays of sentences,where each sentence is an array of words. The 'lang' and'country' arguments are optional, and if omitted, the default locale is used
			切割一個句子到一個數組,每句話放入到一個數組,lang(語系)和country(國家)引數是可選的,如果不寫就預設使用本地語系和國家,返回值是 Array(Array(string),Array(string),Array(string))
			>> SELECT sentences('aa bb ccrr! hello world! hello china! 啊啊! 888! 123')   => [["aa","bb","ccrr"],["hello","world"],["hello","china"],["啊啊"],["888"],["123"]]
			>> 其實按照標點符號切分每句話,一句話放入一個數組中,每句話按照空格切分為多個單詞

46	conv    conv(num, from_base, to_base) - convert num from from_base to to_base  進位制轉換
			>> SELECT conv(11,10,16)    =>B 把10進位制的11轉換為16進位制

47	corr	corr(x,y) - Returns the Pearson coefficient of correlation

48	cos
49	count
50	covar_pop
51	covar_samp
52	crc32
53	create_union    create_union(tag, obj1, obj2, obj3, ...) - Creates a union with the object for given tag
	
54	cume_dist
55	current_database
56	current_date

57	current_timestamp
		>>  SELECT current_timestamp()  		=> 		2019-01-02 20:41:14.514
		>> SELECT date_format(current_timestamp(),'yyyy-MM-dd HH:mm:ss')  => 2019-01-02 20:40:28
58	current_user		current_user() - Returns current user name
		>>  SELECT current_user()  => liyaohui
59	date_add		date_add(start_date, num_days) - Returns the date that is num_days after start_date.
		>> SELECT date_add(to_date('2018-12-10'),22)	=>2019-01-01
60	date_format   	date_format(date/timestamp/string, fmt) - converts a date/timestamp/string to a value of string in the format specified by the date format fmt
		>> SELECT  	date_format(to_date('2018-12-10'),'yyyy/MM/dd')    =>2018/12/10