diff --git a/new-docs/.vuepress/sidebar/en.js b/new-docs/.vuepress/sidebar/en.js index 7c891b0864..3e047a25fa 100644 --- a/new-docs/.vuepress/sidebar/en.js +++ b/new-docs/.vuepress/sidebar/en.js @@ -491,7 +491,6 @@ module.exports = [ initialOpenGroupIndex: -1, children: [ "CREATE-USER", - "ALTER-USER", "CREATE-ROLE", "DROP-ROLE", "DROP-USER", diff --git a/new-docs/.vuepress/sidebar/zh-CN.js b/new-docs/.vuepress/sidebar/zh-CN.js index 6d575f36f5..b25812c9bd 100644 --- a/new-docs/.vuepress/sidebar/zh-CN.js +++ b/new-docs/.vuepress/sidebar/zh-CN.js @@ -491,7 +491,6 @@ module.exports = [ initialOpenGroupIndex: -1, children: [ "CREATE-USER", - "ALTER-USER", "CREATE-ROLE", "DROP-ROLE", "DROP-USER", diff --git a/new-docs/zh-CN/admin-manual/maint-monitor/monitor-metrics/be-metrics.md b/new-docs/zh-CN/admin-manual/maint-monitor/monitor-metrics/be-metrics.md new file mode 100644 index 0000000000..1f4fa9a384 --- /dev/null +++ b/new-docs/zh-CN/admin-manual/maint-monitor/monitor-metrics/be-metrics.md @@ -0,0 +1,28 @@ +--- +{ + "title": "BE 监控项", + "language": "zh-CN" +} +--- + + + +# BE 监控项 + diff --git a/new-docs/zh-CN/admin-manual/maint-monitor/monitor-metrics/fe-metrics.md b/new-docs/zh-CN/admin-manual/maint-monitor/monitor-metrics/fe-metrics.md new file mode 100644 index 0000000000..019353f081 --- /dev/null +++ b/new-docs/zh-CN/admin-manual/maint-monitor/monitor-metrics/fe-metrics.md @@ -0,0 +1,28 @@ +--- +{ + "title": "FE 监控项", + "language": "zh-CN" +} +--- + + + +# FE 监控项 + diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/approx_count_distinct.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/approx_count_distinct.md new file mode 100644 index 0000000000..71e9d2b22e --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/approx_count_distinct.md @@ -0,0 +1,48 @@ +--- +{ + "title": "APPROX_COUNT_DISTINCT", + "language": "zh-CN" +} +--- + + + +# APPROX_COUNT_DISTINCT +## description +### Syntax + +`APPROX_COUNT_DISTINCT(expr)` + + +返回类似于 COUNT(DISTINCT col) 结果的近似值聚合函数。 + +它比 COUNT 和 DISTINCT 组合的速度更快,并使用固定大小的内存,因此对于高基数的列可以使用更少的内存。 + +## example +``` +MySQL > select approx_count_distinct(query_id) from log_statis group by datetime; ++-----------------+ +| approx_count_distinct(`query_id`) | ++-----------------+ +| 17721 | ++-----------------+ +``` +## keyword +APPROX_COUNT_DISTINCT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/avg.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/avg.md new file mode 100644 index 0000000000..142c1dcdab --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/avg.md @@ -0,0 +1,57 @@ +--- +{ + "title": "AVG", + "language": "zh-CN" +} +--- + + + +# AVG +## description +### Syntax + +`AVG([DISTINCT] expr)` + + +用于返回选中字段的平均值 + +可选字段DISTINCT参数可以用来返回去重平均值 + +## example + +``` +mysql> SELECT datetime, AVG(cost_time) FROM log_statis group by datetime; ++---------------------+--------------------+ +| datetime | avg(`cost_time`) | ++---------------------+--------------------+ +| 2019-07-03 21:01:20 | 25.827794561933533 | ++---------------------+--------------------+ + +mysql> SELECT datetime, AVG(distinct cost_time) FROM log_statis group by datetime; ++---------------------+---------------------------+ +| datetime | avg(DISTINCT `cost_time`) | ++---------------------+---------------------------+ +| 2019-07-04 02:23:24 | 20.666666666666668 | ++---------------------+---------------------------+ + +``` +## keyword +AVG diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/bitmap_union.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/bitmap_union.md new file mode 100644 index 0000000000..fd2e72ed3b --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/bitmap_union.md @@ -0,0 +1,146 @@ +--- +{ + "title": "BITMAP_UNION", + "language": "zh-CN" +} +--- + + + +# BITMAP_UNION + +## Create table + +建表时需要使用聚合模型,数据类型是 bitmap , 聚合函数是 bitmap_union + +``` +CREATE TABLE `pv_bitmap` ( + `dt` int(11) NULL COMMENT "", + `page` varchar(10) NULL COMMENT "", + `user_id` bitmap BITMAP_UNION NULL COMMENT "" +) ENGINE=OLAP +AGGREGATE KEY(`dt`, `page`) +COMMENT "OLAP" +DISTRIBUTED BY HASH(`dt`) BUCKETS 2; +``` +注:当数据量很大时,最好为高频率的 bitmap_union 查询建立对应的 rollup 表 + +``` +ALTER TABLE pv_bitmap ADD ROLLUP pv (page, user_id); +``` + +## Data Load + +`TO_BITMAP(expr)` : 将 0 ~ 18446744073709551615 的 unsigned bigint 转为 bitmap + +`BITMAP_EMPTY()`: 生成空 bitmap 列,用于 insert 或导入的时填充默认值 + +`BITMAP_HASH(expr)`: 将任意类型的列通过 Hash 的方式转为 bitmap + +### Stream Load + +``` +cat data | curl --location-trusted -u user:passwd -T - -H "columns: dt,page,user_id, user_id=to_bitmap(user_id)" http://host:8410/api/test/testDb/_stream_load +``` + +``` +cat data | curl --location-trusted -u user:passwd -T - -H "columns: dt,page,user_id, user_id=bitmap_hash(user_id)" http://host:8410/api/test/testDb/_stream_load +``` + +``` +cat data | curl --location-trusted -u user:passwd -T - -H "columns: dt,page,user_id, user_id=bitmap_empty()" http://host:8410/api/test/testDb/_stream_load +``` + +### Insert Into + +id2 的列类型是 bitmap +``` +insert into bitmap_table1 select id, id2 from bitmap_table2; +``` + +id2 的列类型是 bitmap +``` +INSERT INTO bitmap_table1 (id, id2) VALUES (1001, to_bitmap(1000)), (1001, to_bitmap(2000)); +``` + +id2 的列类型是 bitmap +``` +insert into bitmap_table1 select id, bitmap_union(id2) from bitmap_table2 group by id; +``` + +id2 的列类型是 int +``` +insert into bitmap_table1 select id, to_bitmap(id2) from table; +``` + +id2 的列类型是 String +``` +insert into bitmap_table1 select id, bitmap_hash(id_string) from table; +``` + + +## Data Query +### Syntax + + +`BITMAP_UNION(expr)` : 计算输入 Bitmap 的并集,返回新的bitmap + +`BITMAP_UNION_COUNT(expr)`: 计算输入 Bitmap 的并集,返回其基数,和 BITMAP_COUNT(BITMAP_UNION(expr)) 等价。目前推荐优先使用 BITMAP_UNION_COUNT ,其性能优于 BITMAP_COUNT(BITMAP_UNION(expr)) + +`BITMAP_UNION_INT(expr)` : 计算 TINYINT,SMALLINT 和 INT 类型的列中不同值的个数,返回值和 +COUNT(DISTINCT expr) 相同 + +`INTERSECT_COUNT(bitmap_column_to_count, filter_column, filter_values ...)` : 计算满足 +filter_column 过滤条件的多个 bitmap 的交集的基数值。 +bitmap_column_to_count 是 bitmap 类型的列,filter_column 是变化的维度列,filter_values 是维度取值列表 + + +### Example + +下面的 SQL 以上面的 pv_bitmap table 为例: + +计算 user_id 的去重值: + +``` +select bitmap_union_count(user_id) from pv_bitmap; + +select bitmap_count(bitmap_union(user_id)) from pv_bitmap; +``` + +计算 id 的去重值: + +``` +select bitmap_union_int(id) from pv_bitmap; +``` + +计算 user_id 的 留存: + +``` +select intersect_count(user_id, page, 'meituan') as meituan_uv, +intersect_count(user_id, page, 'waimai') as waimai_uv, +intersect_count(user_id, page, 'meituan', 'waimai') as retention //在 'meituan' 和 'waimai' 两个页面都出现的用户数 +from pv_bitmap +where page in ('meituan', 'waimai'); +``` + + +## keyword + +BITMAP,BITMAP_COUNT,BITMAP_EMPTY,BITMAP_UNION,BITMAP_UNION_INT,TO_BITMAP,BITMAP_UNION_COUNT,INTERSECT_COUNT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/count.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/count.md new file mode 100755 index 0000000000..817d7e03f0 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/count.md @@ -0,0 +1,61 @@ +--- +{ + "title": "COUNT", + "language": "zh-CN" +} +--- + + + +# COUNT +## description +### Syntax + +`COUNT([DISTINCT] expr)` + + +用于返回满足要求的行的数目 + +## example + +``` +MySQL > select count(*) from log_statis group by datetime; ++----------+ +| count(*) | ++----------+ +| 28515903 | ++----------+ + +MySQL > select count(datetime) from log_statis group by datetime; ++-------------------+ +| count(`datetime`) | ++-------------------+ +| 28521682 | ++-------------------+ + +MySQL > select count(distinct datetime) from log_statis group by datetime; ++-------------------------------+ +| count(DISTINCT `datetime`) | ++-------------------------------+ +| 71045 | ++-------------------------------+ +``` +## keyword +COUNT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/group_concat.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/group_concat.md new file mode 100644 index 0000000000..8e2a3f4169 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/group_concat.md @@ -0,0 +1,70 @@ +--- +{ + "title": "GROUP_CONCAT", + "language": "zh-CN" +} +--- + + + +# group_concat +## description +### Syntax + +`VARCHAR GROUP_CONCAT(VARCHAR str[, VARCHAR sep])` + + +该函数是类似于 sum() 的聚合函数,group_concat 将结果集中的多行结果连接成一个字符串。第二个参数 sep 为字符串之间的连接符号,该参数可以省略。该函数通常需要和 group by 语句一起使用。 + +## example + +``` +mysql> select value from test; ++-------+ +| value | ++-------+ +| a | +| b | +| c | ++-------+ + +mysql> select GROUP_CONCAT(value) from test; ++-----------------------+ +| GROUP_CONCAT(`value`) | ++-----------------------+ +| a, b, c | ++-----------------------+ + +mysql> select GROUP_CONCAT(value, " ") from test; ++----------------------------+ +| GROUP_CONCAT(`value`, ' ') | ++----------------------------+ +| a b c | ++----------------------------+ + +mysql> select GROUP_CONCAT(value, NULL) from test; ++----------------------------+ +| GROUP_CONCAT(`value`, NULL)| ++----------------------------+ +| NULL | ++----------------------------+ +``` +## keyword +GROUP_CONCAT,GROUP,CONCAT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/hll_union_agg.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/hll_union_agg.md new file mode 100644 index 0000000000..7e3b0e1a04 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/hll_union_agg.md @@ -0,0 +1,52 @@ +--- +{ + "title": "HLL_UNION_AGG", + "language": "zh-CN" +} +--- + + + +# HLL_UNION_AGG +## description +### Syntax + +`HLL_UNION_AGG(hll)` + + +HLL是基于HyperLogLog算法的工程实现,用于保存HyperLogLog计算过程的中间结果 + +它只能作为表的value列类型、通过聚合来不断的减少数据量,以此来实现加快查询的目的 + +基于它得到的是一个估算结果,误差大概在1%左右,hll列是通过其它列或者导入数据里面的数据生成的 + +导入的时候通过hll_hash函数来指定数据中哪一列用于生成hll列,它常用于替代count distinct,通过结合rollup在业务上用于快速计算uv等 + +## example +``` +MySQL > select HLL_UNION_AGG(uv_set) from test_uv;; ++-------------------------+ +| HLL_UNION_AGG(`uv_set`) | ++-------------------------+ +| 17721 | ++-------------------------+ +``` +## keyword +HLL_UNION_AGG,HLL,UNION,AGG diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/max.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/max.md new file mode 100755 index 0000000000..22522c65a1 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/max.md @@ -0,0 +1,46 @@ +--- +{ + "title": "MAX", + "language": "zh-CN" +} +--- + + + +# MAX +## description +### Syntax + +`MAX(expr)` + + +返回expr表达式的最大值 + +## example +``` +MySQL > select max(scan_rows) from log_statis group by datetime; ++------------------+ +| max(`scan_rows`) | ++------------------+ +| 4671587 | ++------------------+ +``` +## keyword +MAX diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/min.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/min.md new file mode 100755 index 0000000000..93406089fb --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/min.md @@ -0,0 +1,46 @@ +--- +{ + "title": "MIN", + "language": "zh-CN" +} +--- + + + +# MIN +## description +### Syntax + +`MIN(expr)` + + +返回expr表达式的最小值 + +## example +``` +MySQL > select min(scan_rows) from log_statis group by datetime; ++------------------+ +| min(`scan_rows`) | ++------------------+ +| 0 | ++------------------+ +``` +## keyword +MIN diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/percentile.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/percentile.md new file mode 100755 index 0000000000..dfbe24f30d --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/percentile.md @@ -0,0 +1,57 @@ +--- +{ + "title": "PERCENTILE", + "language": "zh-CN" +} +--- + + + +# PERCENTILE +## description +### Syntax + +`PERCENTILE(expr, DOUBLE p)` + +计算精确的百分位数,适用于小数据量。先对指定列降序排列,然后取精确的第 p 位百分数。p的值介于0到1之间 + +参数说明 +expr:必填。值为整数(最大为bigint) 类型的列。 +p:必填。需要精确的百分位数。取值为 [0.0,1.0]。 + +## example +``` +MySQL > select `table`, percentile(cost_time,0.99) from log_statis group by `table`; ++---------------------+---------------------------+ +| table | percentile(`cost_time`, 0.99) | ++----------+--------------------------------------+ +| test | 54.22 | ++----------+--------------------------------------+ + +MySQL > select percentile(NULL,0.3) from table1; ++-----------------------+ +| percentile(NULL, 0.3) | ++-----------------------+ +| NULL | ++-----------------------+ +``` + +## keyword +PERCENTILE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/percentile_approx.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/percentile_approx.md new file mode 100755 index 0000000000..19c68be84f --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/percentile_approx.md @@ -0,0 +1,59 @@ +--- +{ + "title": "PERCENTILE_APPROX", + "language": "zh-CN" +} +--- + + + +# PERCENTILE_APPROX +## description +### Syntax + +`PERCENTILE_APPROX(expr, DOUBLE p[, DOUBLE compression])` + + +返回第p个百分位点的近似值,p的值介于0到1之间 + +compression参数是可选项,可设置范围是[2048, 10000],值越大,精度越高,内存消耗越大,计算耗时越长。 +compression参数未指定或设置的值在[2048, 10000]范围外,以10000的默认值运行 + +该函数使用固定大小的内存,因此对于高基数的列可以使用更少的内存,可用于计算tp99等统计值 + +## example +``` +MySQL > select `table`, percentile_approx(cost_time,0.99) from log_statis group by `table`; ++---------------------+---------------------------+ +| table | percentile_approx(`cost_time`, 0.99) | ++----------+--------------------------------------+ +| test | 54.22 | ++----------+--------------------------------------+ + +MySQL > select `table`, percentile_approx(cost_time,0.99, 4096) from log_statis group by `table`; ++---------------------+---------------------------+ +| table | percentile_approx(`cost_time`, 0.99, 4096.0) | ++----------+--------------------------------------+ +| test | 54.21 | ++----------+--------------------------------------+ +``` + +## keyword +PERCENTILE_APPROX,PERCENTILE,APPROX diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/stddev.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/stddev.md new file mode 100755 index 0000000000..2a06d4e741 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/stddev.md @@ -0,0 +1,53 @@ +--- +{ + "title": "STDDEV,STDDEV_POP", + "language": "zh-CN" +} +--- + + + +# STDDEV,STDDEV_POP +## description +### Syntax + +`STDDEV(expr)` + + +返回expr表达式的标准差 + +## example +``` +MySQL > select stddev(scan_rows) from log_statis group by datetime; ++---------------------+ +| stddev(`scan_rows`) | ++---------------------+ +| 2.3736656687790934 | ++---------------------+ + +MySQL > select stddev_pop(scan_rows) from log_statis group by datetime; ++-------------------------+ +| stddev_pop(`scan_rows`) | ++-------------------------+ +| 2.3722760595994914 | ++-------------------------+ +``` +## keyword +STDDEV,STDDEV_POP,POP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/stddev_samp.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/stddev_samp.md new file mode 100755 index 0000000000..3c7b505ed2 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/stddev_samp.md @@ -0,0 +1,46 @@ +--- +{ + "title": "STDDEV_SAMP", + "language": "zh-CN" +} +--- + + + +# STDDEV_SAMP +## description +### Syntax + +`STDDEV_SAMP(expr)` + + +返回expr表达式的样本标准差 + +## example +``` +MySQL > select stddev_samp(scan_rows) from log_statis group by datetime; ++--------------------------+ +| stddev_samp(`scan_rows`) | ++--------------------------+ +| 2.372044195280762 | ++--------------------------+ +``` +## keyword +STDDEV_SAMP,STDDEV,SAMP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/sum.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/sum.md new file mode 100755 index 0000000000..abec502baa --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/sum.md @@ -0,0 +1,46 @@ +--- +{ + "title": "SUM", + "language": "zh-CN" +} +--- + + + +# SUM +## description +### Syntax + +`SUM(expr)` + + +用于返回选中字段所有值的和 + +## example +``` +MySQL > select sum(scan_rows) from log_statis group by datetime; ++------------------+ +| sum(`scan_rows`) | ++------------------+ +| 8217360135 | ++------------------+ +``` +## keyword +SUM diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/topn.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/topn.md new file mode 100644 index 0000000000..11c4544076 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/topn.md @@ -0,0 +1,60 @@ +--- +{ + "title": "TOPN", + "language": "zh-CN" +} +--- + + + +# TOPN +## description +### Syntax + +`topn(expr, INT top_num[, INT space_expand_rate])` + +该topn函数使用Space-Saving算法计算expr中的top_num个频繁项,结果为频繁项及其出现次数,该结果为近似值 + +space_expand_rate参数是可选项,该值用来设置Space-Saving算法中使用的counter个数 +``` +counter numbers = top_num * space_expand_rate +``` +space_expand_rate的值越大,结果越准确,默认值为50 + +## example +``` +MySQL [test]> select topn(keyword,10) from keyword_table where date>= '2020-06-01' and date <= '2020-06-19' ; ++------------------------------------------------------------------------------------------------------------+ +| topn(`keyword`, 10) | ++------------------------------------------------------------------------------------------------------------+ +| a:157, b:138, c:133, d:133, e:131, f:127, g:124, h:122, i:117, k:117 | ++------------------------------------------------------------------------------------------------------------+ + +MySQL [test]> select date,topn(keyword,10,100) from keyword_table where date>= '2020-06-17' and date <= '2020-06-19' group by date; ++------------+-----------------------------------------------------------------------------------------------+ +| date | topn(`keyword`, 10, 100) | ++------------+-----------------------------------------------------------------------------------------------+ +| 2020-06-19 | a:11, b:8, c:8, d:7, e:7, f:7, g:7, h:7, i:7, j:7 | +| 2020-06-18 | a:10, b:8, c:7, f:7, g:7, i:7, k:7, l:7, m:6, d:6 | +| 2020-06-17 | a:9, b:8, c:8, j:8, d:7, e:7, f:7, h:7, i:7, k:7 | ++------------+-----------------------------------------------------------------------------------------------+ +``` +## keyword +TOPN \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/var_samp.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/var_samp.md new file mode 100755 index 0000000000..90010e9c58 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/var_samp.md @@ -0,0 +1,47 @@ +--- +{ + "title": "VAR_SAMP,VARIANCE_SAMP", + "language": "zh-CN" +} +--- + + + +# VAR_SAMP,VARIANCE_SAMP +## description +### Syntax + +`VAR_SAMP(expr)` + + +返回expr表达式的样本方差 + +## example +``` +MySQL > select var_samp(scan_rows) from log_statis group by datetime; ++-----------------------+ +| var_samp(`scan_rows`) | ++-----------------------+ +| 5.6227132145741789 | ++-----------------------+ +``` + +## keyword +VAR_SAMP,VARIANCE_SAMP,VAR,SAMP,VARIANCE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/variance.md b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/variance.md new file mode 100755 index 0000000000..2006a3c50f --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/variance.md @@ -0,0 +1,54 @@ +--- +{ + "title": "VARIANCE,VAR_POP,VARIANCE_POP", + "language": "zh-CN" +} +--- + + + +# VARIANCE,VAR_POP,VARIANCE_POP +## description +### Syntax + +`VARIANCE(expr)` + + +返回expr表达式的方差 + +## example +``` +MySQL > select variance(scan_rows) from log_statis group by datetime; ++-----------------------+ +| variance(`scan_rows`) | ++-----------------------+ +| 5.6183332881176211 | ++-----------------------+ + +MySQL > select var_pop(scan_rows) from log_statis group by datetime; ++----------------------+ +| var_pop(`scan_rows`) | ++----------------------+ +| 5.6230744719006163 | ++----------------------+ +``` + +## keyword +VARIANCE,VAR_POP,VARIANCE_POP,VAR,POP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and.md new file mode 100644 index 0000000000..9a8ba628b9 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and.md @@ -0,0 +1,83 @@ +--- +{ + "title": "bitmap_and", + "language": "zh-CN" +} +--- + + + +# bitmap_and +## description +### Syntax + +`BITMAP BITMAP_AND(BITMAP lhs, BITMAP rhs)` + +计算两个及以上输入bitmap的交集,返回新的bitmap. + +## example + +``` +mysql> select bitmap_count(bitmap_and(to_bitmap(1), to_bitmap(2))) cnt; ++------+ +| cnt | ++------+ +| 0 | ++------+ + +mysql> select bitmap_count(bitmap_and(to_bitmap(1), to_bitmap(1))) cnt; ++------+ +| cnt | ++------+ +| 1 | ++------+ + +MySQL> select bitmap_to_string(bitmap_and(to_bitmap(1), to_bitmap(1))); ++----------------------------------------------------------+ +| bitmap_to_string(bitmap_and(to_bitmap(1), to_bitmap(1))) | ++----------------------------------------------------------+ +| 1 | ++----------------------------------------------------------+ + +MySQL> select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))); ++-----------------------------------------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) | ++-----------------------------------------------------------------------------------------------------------------------+ +| 1,2 | ++-----------------------------------------------------------------------------------------------------------------------+ + +MySQL> select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty())); ++---------------------------------------------------------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), bitmap_empty())) | ++---------------------------------------------------------------------------------------------------------------------------------------+ +| | ++---------------------------------------------------------------------------------------------------------------------------------------+ + +MySQL> select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),NULL)); ++-----------------------------------------------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL)) | ++-----------------------------------------------------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------------------------------------------------+ +``` + +## keyword + + BITMAP_AND,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and_count.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and_count.md new file mode 100644 index 0000000000..7e1c1b5cbc --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and_count.md @@ -0,0 +1,84 @@ +--- +{ + "title": "bitmap_and_count", + "language": "zh-CN" +} +--- + + + +# bitmap_and_count +## description +### Syntax + +`BigIntVal bitmap_and_count(BITMAP lhs, BITMAP rhs, ...)` + +计算两个及以上输入bitmap的交集,返回交集的个数. + +## example + +``` +MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_empty()); ++---------------------------------------------------------------+ +| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_empty()) | ++---------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------+ + + +MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')); ++----------------------------------------------------------------------------+ +| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2,3')) | ++----------------------------------------------------------------------------+ +| 3 | ++----------------------------------------------------------------------------+ + +MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')); ++----------------------------------------------------------------------------+ +| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5')) | ++----------------------------------------------------------------------------+ +| 1 | ++----------------------------------------------------------------------------+ + +MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5')); ++-------------------------------------------------------------------------------------------------------------+ +| (bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) | ++-------------------------------------------------------------------------------------------------------------+ +| 2 | ++-------------------------------------------------------------------------------------------------------------+ + +MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty()); ++-----------------------------------------------------------------------------------------------------------------------------+ +| (bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), bitmap_empty())) | ++-----------------------------------------------------------------------------------------------------------------------------+ +| 0 | ++-----------------------------------------------------------------------------------------------------------------------------+ + +MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL); ++-------------------------------------------------------------------------------------------------------------------+ +| (bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL)) | ++-------------------------------------------------------------------------------------------------------------------+ +| NULL | ++-------------------------------------------------------------------------------------------------------------------+ +``` + +## keyword + + BITMAP_AND_COUNT,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and_not.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and_not.md new file mode 100644 index 0000000000..7074d19273 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and_not.md @@ -0,0 +1,48 @@ +--- +{ + "title": "bitmap_and_not", + "language": "zh-CN" +} +--- + + + +# bitmap_and_not +## description +### Syntax + +`BITMAP BITMAP_AND_NOT(BITMAP lhs, BITMAP rhs)` + +将两个bitmap进行与非操作并返回计算结果。 + +## example + +``` +mysql> select bitmap_count(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'))) cnt; ++------+ +| cnt | ++------+ +| 2 | ++------+ +``` + +## keyword + + BITMAP_AND_NOT,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and_not_count.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and_not_count.md new file mode 100644 index 0000000000..509d01a9b4 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_and_not_count.md @@ -0,0 +1,48 @@ +--- +{ + "title": "bitmap_and_not_count", + "language": "zh-CN" +} +--- + + + +# bitmap_and_not_count +## description +### Syntax + +`BITMAP BITMAP_AND_NOT_COUNT(BITMAP lhs, BITMAP rhs)` + +将两个bitmap进行与非操作并返回计算返回的大小. + +## example + +``` +mysql> select bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) cnt; ++------+ +| cnt | ++------+ +| 2 | ++------+ +``` + +## keyword + + BITMAP_AND_NOT_COUNT,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_contains.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_contains.md new file mode 100644 index 0000000000..1f3f67c928 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_contains.md @@ -0,0 +1,55 @@ +--- +{ + "title": "bitmap_contains", + "language": "zh-CN" +} +--- + + + +# bitmap_contains +## description +### Syntax + +`B00LEAN BITMAP_CONTAINS(BITMAP bitmap, BIGINT input)` + +计算输入值是否在Bitmap列中,返回值是Boolean值. + +## example + +``` +mysql> select bitmap_contains(to_bitmap(1),2) cnt; ++------+ +| cnt | ++------+ +| 0 | ++------+ + +mysql> select bitmap_contains(to_bitmap(1),1) cnt; ++------+ +| cnt | ++------+ +| 1 | ++------+ +``` + +## keyword + + BITMAP_CONTAINS,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_empty.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_empty.md new file mode 100644 index 0000000000..e6d3d72707 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_empty.md @@ -0,0 +1,52 @@ +--- +{ + "title": "bitmap_empty", + "language": "zh-CN" +} +--- + + + +# bitmap_empty +## description +### Syntax + +`BITMAP BITMAP_EMPTY()` + +返回一个空bitmap。主要用于 insert 或 stream load 时填充默认值。例如 + +``` +cat data | curl --location-trusted -u user:passwd -T - -H "columns: dt,page,v1,v2=bitmap_empty()" http://host:8410/api/test/testDb/_stream_load +``` + +## example + +``` +mysql> select bitmap_count(bitmap_empty()); ++------------------------------+ +| bitmap_count(bitmap_empty()) | ++------------------------------+ +| 0 | ++------------------------------+ +``` + +## keyword + + BITMAP_EMPTY,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_from_string.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_from_string.md new file mode 100644 index 0000000000..355ff946e4 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_from_string.md @@ -0,0 +1,63 @@ +--- +{ + "title": "bitmap_from_string", + "language": "zh-CN" +} +--- + + + +# bitmap_from_string + +## description +### Syntax + +`BITMAP BITMAP_FROM_STRING(VARCHAR input)` + +将一个字符串转化为一个BITMAP,字符串是由逗号分隔的一组UINT32数字组成. +比如"0, 1, 2"字符串会转化为一个Bitmap,其中的第0, 1, 2位被设置. +当输入字段不合法时,返回NULL + +## example + +``` +mysql> select bitmap_to_string(bitmap_empty()); ++----------------------------------+ +| bitmap_to_string(bitmap_empty()) | ++----------------------------------+ +| | ++----------------------------------+ + +mysql> select bitmap_to_string(bitmap_from_string("0, 1, 2")); ++-------------------------------------------------+ +| bitmap_to_string(bitmap_from_string('0, 1, 2')) | ++-------------------------------------------------+ +| 0,1,2 | ++-------------------------------------------------+ + +mysql> select bitmap_from_string("-1, 0, 1, 2"); ++-----------------------------------+ +| bitmap_from_string('-1, 0, 1, 2') | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +``` + +## keyword + + BITMAP_FROM_STRING,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_has_all.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_has_all.md new file mode 100644 index 0000000000..71ec5d8006 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_has_all.md @@ -0,0 +1,56 @@ +--- +{ + "title": "bitmap_has_all", + "language": "zh-CN" +} +--- + + + +# bitmap_has_all +## description +### Syntax + +`B00LEAN BITMAP_HAS_ALL(BITMAP lhs, BITMAP rhs)` + +如果第一个bitmap包含第二个bitmap的全部元素,则返回true。 +如果第二个bitmap包含的元素为空,返回true。 + +## example + +``` +mysql> select bitmap_has_all(bitmap_from_string("0, 1, 2"), bitmap_from_string("1, 2")) cnt; ++------+ +| cnt | ++------+ +| 1 | ++------+ + +mysql> select bitmap_has_all(bitmap_empty(), bitmap_from_string("1, 2")) cnt; ++------+ +| cnt | ++------+ +| 0 | ++------+ +``` + +## keyword + + BITMAP_HAS_ALL,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_has_any.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_has_any.md new file mode 100644 index 0000000000..13fc421732 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_has_any.md @@ -0,0 +1,55 @@ +--- +{ + "title": "bitmap_has_any", + "language": "zh-CN" +} +--- + + + +# bitmap_has_any +## description +### Syntax + +`B00LEAN BITMAP_HAS_ANY(BITMAP lhs, BITMAP rhs)` + +计算两个Bitmap列是否存在相交元素,返回值是Boolean值. + +## example + +``` +mysql> select bitmap_has_any(to_bitmap(1),to_bitmap(2)) cnt; ++------+ +| cnt | ++------+ +| 0 | ++------+ + +mysql> select bitmap_has_any(to_bitmap(1),to_bitmap(1)) cnt; ++------+ +| cnt | ++------+ +| 1 | ++------+ +``` + +## keyword + + BITMAP_HAS_ANY,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_hash.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_hash.md new file mode 100644 index 0000000000..76eda65e91 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_hash.md @@ -0,0 +1,52 @@ +--- +{ + "title": "bitmap_hash", + "language": "zh-CN" +} +--- + + + +# bitmap_hash +## description +### Syntax + +`BITMAP BITMAP_HASH(expr)` + +对任意类型的输入计算32位的哈希值,返回包含该哈希值的bitmap。主要用于stream load任务将非整型字段导入Doris表的bitmap字段。例如 + +``` +cat data | curl --location-trusted -u user:passwd -T - -H "columns: dt,page,device_id, device_id=bitmap_hash(device_id)" http://host:8410/api/test/testDb/_stream_load +``` + +## example + +``` +mysql> select bitmap_count(bitmap_hash('hello')); ++------------------------------------+ +| bitmap_count(bitmap_hash('hello')) | ++------------------------------------+ +| 1 | ++------------------------------------+ +``` + +## keyword + + BITMAP_HASH,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_intersect.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_intersect.md new file mode 100644 index 0000000000..3b71de439b --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_intersect.md @@ -0,0 +1,62 @@ +--- +{ + "title": "bitmap_intersect", + "language": "zh-CN" +} +--- + + + +# bitmap_intersect +## description + +聚合函数,用于计算分组后的 bitmap 交集。常见使用场景如:计算用户留存率。 + +### Syntax + +`BITMAP BITMAP_INTERSECT(BITMAP value)` + +输入一组 bitmap 值,求这一组 bitmap 值的交集,并返回。 + +## example + +表结构 + +``` +KeysType: AGG_KEY +Columns: tag varchar, date datetime, user_id bitmap bitmap_union + +``` + +``` +求今天和昨天不同 tag 下的用户留存 +mysql> select tag, bitmap_intersect(user_id) from (select tag, date, bitmap_union(user_id) user_id from table where date in ('2020-05-18', '2020-05-19') group by tag, date) a group by tag; +``` + +和 bitmap_to_string 函数组合使用可以获取交集的具体数据 + +``` +求今天和昨天不同 tag 下留存的用户都是哪些 +mysql> select tag, bitmap_to_string(bitmap_intersect(user_id)) from (select tag, date, bitmap_union(user_id) user_id from table where date in ('2020-05-18', '2020-05-19') group by tag, date) a group by tag; +``` + +## keyword + + BITMAP_INTERSECT, BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_max.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_max.md new file mode 100644 index 0000000000..e9b6e3772f --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_max.md @@ -0,0 +1,55 @@ +--- +{ + "title": "bitmap_max", + "language": "zh-CN" +} +--- + + + +# bitmap_max +## description +### Syntax + +`BIGINT BITMAP_MAX(BITMAP input)` + +计算并返回 bitmap 中的最大值. + +## example + +``` +mysql> select bitmap_max(bitmap_from_string('')) value; ++-------+ +| value | ++-------+ +| NULL | ++-------+ + +mysql> select bitmap_max(bitmap_from_string('1,9999999999')) value; ++------------+ +| value | ++------------+ +| 9999999999 | ++------------+ +``` + +## keyword + + BITMAP_MAX,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_min.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_min.md new file mode 100644 index 0000000000..09e8486189 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_min.md @@ -0,0 +1,55 @@ +--- +{ + "title": "bitmap_min", + "language": "zh-CN" +} +--- + + + +# bitmap_min +## description +### Syntax + +`BIGINT BITMAP_MIN(BITMAP input)` + +计算并返回 bitmap 中的最小值. + +## example + +``` +mysql> select bitmap_min(bitmap_from_string('')) value; ++-------+ +| value | ++-------+ +| NULL | ++-------+ + +mysql> select bitmap_min(bitmap_from_string('1,9999999999')) value; ++-------+ +| value | ++-------+ +| 1 | ++-------+ +``` + +## keyword + + BITMAP_MIN,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_not.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_not.md new file mode 100644 index 0000000000..28838941d3 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_not.md @@ -0,0 +1,55 @@ +--- +{ + "title": "bitmap_not", + "language": "zh-CN" +} +--- + + + +# bitmap_not +## description +### Syntax + +`BITMAP BITMAP_NOT(BITMAP lhs, BITMAP rhs)` + +计算lhs减去rhs之后的集合,返回新的bitmap. + +## example + +``` +mysql> select bitmap_count(bitmap_not(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'))) cnt; ++------+ +| cnt | ++------+ +| 0 | ++------+ + +mysql> select bitmap_to_string(bitmap_not(bitmap_from_string('2,3,5'),bitmap_from_string('1,2,3,4'))); ++----------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_xor(bitmap_from_string('2,3,5'), bitmap_from_string('1,2,3,4'))) | ++----------------------------------------------------------------------------------------+ +| 5 | ++----------------------------------------------------------------------------------------+ +``` + +## keyword + + BITMAP_NOT,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_or.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_or.md new file mode 100644 index 0000000000..ef0eeaa6af --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_or.md @@ -0,0 +1,83 @@ +--- +{ + "title": "bitmap_or", + "language": "zh-CN" +} +--- + + + +# bitmap_or +## description +### Syntax + +`BITMAP BITMAP_OR(BITMAP lhs, BITMAP rhs, ...)` + +计算两个及以上的输入bitmap的并集,返回新的bitmap. + +## example + +``` +mysql> select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(2))) cnt; ++------+ +| cnt | ++------+ +| 2 | ++------+ + +mysql> select bitmap_count(bitmap_or(to_bitmap(1), to_bitmap(1))) cnt; ++------+ +| cnt | ++------+ +| 1 | ++------+ + +MySQL> select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))); ++---------------------------------------------------------+ +| bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))) | ++---------------------------------------------------------+ +| 1,2 | ++---------------------------------------------------------+ + +MySQL> select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), NULL)); ++--------------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), NULL)) | ++--------------------------------------------------------------------------------------------+ +| NULL | ++--------------------------------------------------------------------------------------------+ + +MySQL> select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), bitmap_empty())); ++------------------------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2), to_bitmap(10), to_bitmap(0), bitmap_empty())) | ++------------------------------------------------------------------------------------------------------+ +| 0,1,2,10 | ++------------------------------------------------------------------------------------------------------+ + +MySQL> select bitmap_to_string(bitmap_or(to_bitmap(10), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))); ++--------------------------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_or(to_bitmap(10), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) | ++--------------------------------------------------------------------------------------------------------+ +| 1,2,3,4,5,10 | ++--------------------------------------------------------------------------------------------------------+ +``` + +## keyword + + BITMAP_OR,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_or_count.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_or_count.md new file mode 100644 index 0000000000..6e1104bf21 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_or_count.md @@ -0,0 +1,77 @@ +--- +{ + "title": "bitmap_or_count", + "language": "zh-CN" +} +--- + + + +# bitmap_or_count +## description +### Syntax + +`BigIntVal bitmap_or_count(BITMAP lhs, BITMAP rhs, ...)` + +计算两个及以上输入bitmap的并集,返回并集的个数. + +## example + +``` +MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_empty()); ++--------------------------------------------------------------+ +| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_empty()) | ++--------------------------------------------------------------+ +| 3 | ++--------------------------------------------------------------+ + + +MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')); ++---------------------------------------------------------------------------+ +| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2,3')) | ++---------------------------------------------------------------------------+ +| 3 | ++---------------------------------------------------------------------------+ + +MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')); ++---------------------------------------------------------------------------+ +| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5')) | ++---------------------------------------------------------------------------+ +| 5 | ++---------------------------------------------------------------------------+ + +MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5'), to_bitmap(100), bitmap_empty()); ++-----------------------------------------------------------------------------------------------------------+ +| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5'), to_bitmap(100), bitmap_empty()) | ++-----------------------------------------------------------------------------------------------------------+ +| 6 | ++-----------------------------------------------------------------------------------------------------------+ + +MySQL> select bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5'), to_bitmap(100), NULL); ++-------------------------------------------------------------------------------------------------+ +| bitmap_or_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5'), to_bitmap(100), NULL) | ++-------------------------------------------------------------------------------------------------+ +| NULL | ++-------------------------------------------------------------------------------------------------+ +``` + +## keyword + + BITMAP_OR_COUNT,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_subset_in_range.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_subset_in_range.md new file mode 100644 index 0000000000..5fb673b1ad --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_subset_in_range.md @@ -0,0 +1,57 @@ +--- +{ + "title": "bitmap_subset_in_range", + "language": "zh-CN" +} +--- + + + +# bitmap_subset_in_range + +## Description + +### Syntax + +`BITMAP BITMAP_SUBSET_IN_RANGE(BITMAP src, BIGINT range_start, BIGINT range_end)` + +返回 BITMAP 指定范围内的子集(不包括范围结束)。 + +## example + +``` +mysql> select bitmap_to_string(bitmap_subset_in_range(bitmap_from_string('1,2,3,4,5'), 0, 9)) value; ++-----------+ +| value | ++-----------+ +| 1,2,3,4,5 | ++-----------+ + +mysql> select bitmap_to_string(bitmap_subset_in_range(bitmap_from_string('1,2,3,4,5'), 2, 3)) value; ++-------+ +| value | ++-------+ +| 2 | ++-------+ +``` + +## keyword + + BITMAP_SUBSET_IN_RANGE,BITMAP_SUBSET,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_subset_limit.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_subset_limit.md new file mode 100644 index 0000000000..be905b5637 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_subset_limit.md @@ -0,0 +1,59 @@ +--- +{ + "title": "bitmap_subset_limit", + "language": "zh-CN" +} +--- + + + +# bitmap_subset_limit + +## Description + +### Syntax + +`BITMAP BITMAP_SUBSET_LIMIT(BITMAP src, BIGINT range_start, BIGINT cardinality_limit)` + +生成 src 的子 BITMAP, 从不小于 range_start 的位置开始,大小限制为 cardinality_limit 。 +range_start:范围起始点(含) +cardinality_limit:子BIGMAP基数上限 + +## example + +``` +mysql> select bitmap_to_string(bitmap_subset_limit(bitmap_from_string('1,2,3,4,5'), 0, 3)) value; ++-----------+ +| value | ++-----------+ +| 1,2,3 | ++-----------+ + +mysql> select bitmap_to_string(bitmap_subset_limit(bitmap_from_string('1,2,3,4,5'), 4, 3)) value; ++-------+ +| value | ++-------+ +| 4,5 | ++-------+ +``` + +## keyword + + BITMAP_SUBSET_LIMIT,BITMAP_SUBSET,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_to_string.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_to_string.md new file mode 100644 index 0000000000..ba447171f6 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_to_string.md @@ -0,0 +1,69 @@ +--- +{ + "title": "bitmap_to_string", + "language": "zh-CN" +} +--- + + + +# bitmap_to_string + +## description +### Syntax + +`VARCHAR BITMAP_TO_STRING(BITMAP input)` + +将一个bitmap转化成一个逗号分隔的字符串,字符串中包含所有设置的BIT位。输入是null的话会返回null。 + +## example + +``` +mysql> select bitmap_to_string(null); ++------------------------+ +| bitmap_to_string(NULL) | ++------------------------+ +| NULL | ++------------------------+ + +mysql> select bitmap_to_string(bitmap_empty()); ++----------------------------------+ +| bitmap_to_string(bitmap_empty()) | ++----------------------------------+ +| | ++----------------------------------+ + +mysql> select bitmap_to_string(to_bitmap(1)); ++--------------------------------+ +| bitmap_to_string(to_bitmap(1)) | ++--------------------------------+ +| 1 | ++--------------------------------+ + +mysql> select bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))); ++---------------------------------------------------------+ +| bitmap_to_string(bitmap_or(to_bitmap(1), to_bitmap(2))) | ++---------------------------------------------------------+ +| 1,2 | ++---------------------------------------------------------+ + +``` + +## keyword + + BITMAP_TO_STRING,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_union.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_union.md new file mode 100644 index 0000000000..8dde6b4fb1 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_union.md @@ -0,0 +1,59 @@ +--- +{ + "title": "bitmap_union", + "language": "zh-CN" +} +--- + + + +# bitmap_union function + +## description + +聚合函数,用于计算分组后的 bitmap 并集。常见使用场景如:计算PV,UV。 + +### Syntax + +`BITMAP BITMAP_UNION(BITMAP value)` + +输入一组 bitmap 值,求这一组 bitmap 值的并集,并返回。 + +## example + +``` +mysql> select page_id, bitmap_union(user_id) from table group by page_id; +``` + +和 bitmap_count 函数组合使用可以求得网页的 UV 数据 + +``` +mysql> select page_id, bitmap_count(bitmap_union(user_id)) from table group by page_id; +``` + +当 user_id 字段为 int 时,上面查询语义等同于 + +``` +mysql> select page_id, count(distinct user_id) from table group by page_id; +``` + +## keyword + + BITMAP_UNION, BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_xor.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_xor.md new file mode 100644 index 0000000000..a50cdbca16 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_xor.md @@ -0,0 +1,76 @@ +--- +{ + "title": "bitmap_xor", + "language": "zh-CN" +} +--- + + + +# bitmap_xor +## description +### Syntax + +`BITMAP BITMAP_XOR(BITMAP lhs, BITMAP rhs, ...)` + +计算两个及以上输入bitmap的差集,返回新的bitmap. + +## example + +``` +mysql> select bitmap_count(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'))) cnt; ++------+ +| cnt | ++------+ +| 2 | ++------+ + +mysql> select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'))); ++----------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'))) | ++----------------------------------------------------------------------------------------+ +| 1,4 | ++----------------------------------------------------------------------------------------+ + +MySQL> select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'))); ++---------------------------------------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'))) | ++---------------------------------------------------------------------------------------------------------------------+ +| 1,3,5 | ++---------------------------------------------------------------------------------------------------------------------+ + +MySQL> select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),bitmap_empty())); ++-------------------------------------------------------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'), bitmap_empty())) | ++-------------------------------------------------------------------------------------------------------------------------------------+ +| 1,3,5 | ++-------------------------------------------------------------------------------------------------------------------------------------+ + +MySQL> select bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)); ++---------------------------------------------------------------------------------------------------------------------------+ +| bitmap_to_string(bitmap_xor(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'), NULL)) | ++---------------------------------------------------------------------------------------------------------------------------+ +| NULL | ++---------------------------------------------------------------------------------------------------------------------------+ +``` + +## keyword + + BITMAP_XOR,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_xor_count.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_xor_count.md new file mode 100644 index 0000000000..65b0a7e64f --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/bitmap_xor_count.md @@ -0,0 +1,84 @@ +--- +{ + "title": "bitmap_xor_count", + "language": "zh-CN" +} +--- + + + +# bitmap_xor_count + +## description + +### Syntax + +`BIGINT BITMAP_XOR_COUNT(BITMAP lhs, BITMAP rhs, ...)` + +将两个及以上bitmap集合进行异或操作并返回结果集的大小 + +## example + +``` +mysql> select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')); ++----------------------------------------------------------------------------+ +| bitmap_xor_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5')) | ++----------------------------------------------------------------------------+ +| 4 | ++----------------------------------------------------------------------------+ + +mysql> select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3')); ++----------------------------------------------------------------------------+ +| bitmap_xor_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2,3')) | ++----------------------------------------------------------------------------+ +| 0 | ++----------------------------------------------------------------------------+ + +mysql> select bitmap_xor_count(bitmap_from_string('1,2,3'),bitmap_from_string('4,5,6')); ++----------------------------------------------------------------------------+ +| bitmap_xor_count(bitmap_from_string('1,2,3'), bitmap_from_string('4,5,6')) | ++----------------------------------------------------------------------------+ +| 6 | ++----------------------------------------------------------------------------+ + +MySQL> select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'))); ++-----------------------------------------------------------------------------------------------------------+ +| (bitmap_xor_count(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'))) | ++-----------------------------------------------------------------------------------------------------------+ +| 3 | ++-----------------------------------------------------------------------------------------------------------+ + +MySQL> select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),bitmap_empty())); ++---------------------------------------------------------------------------------------------------------------------------+ +| (bitmap_xor_count(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'), bitmap_empty())) | ++---------------------------------------------------------------------------------------------------------------------------+ +| 3 | ++---------------------------------------------------------------------------------------------------------------------------+ + +MySQL> select (bitmap_xor_count(bitmap_from_string('2,3'),bitmap_from_string('1,2,3,4'),bitmap_from_string('3,4,5'),NULL)); ++-----------------------------------------------------------------------------------------------------------------+ +| (bitmap_xor_count(bitmap_from_string('2,3'), bitmap_from_string('1,2,3,4'), bitmap_from_string('3,4,5'), NULL)) | ++-----------------------------------------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------------------------------------+ +``` + +## keyword + + BITMAP_XOR_COUNT,BITMAP + diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/orthogonal_bitmap_intersect.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/orthogonal_bitmap_intersect.md new file mode 100644 index 0000000000..6d98be6699 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/orthogonal_bitmap_intersect.md @@ -0,0 +1,47 @@ +--- +{ +"title": "orthogonal_bitmap_intersect", +"language": "zh-CN" +} +--- + + + +# orthogonal_bitmap_intersect +## description +### Syntax + +`BITMAP ORTHOGONAL_BITMAP_INTERSECT(bitmap_column, column_to_filter, filter_values)` +求bitmap交集函数, 第一个参数是Bitmap列,第二个参数是用来过滤的维度列,第三个参数是变长参数,含义是过滤维度列的不同取值 + +## example + +``` +mysql> select orthogonal_bitmap_intersect(members, tag_group, 1150000, 1150001, 390006) from tag_map where tag_group in ( 1150000, 1150001, 390006); ++-------------------------------------------------------------------------------+ +| orthogonal_bitmap_intersect(`members`, `tag_group`, 1150000, 1150001, 390006) | ++-------------------------------------------------------------------------------+ +| NULL | ++-------------------------------------------------------------------------------+ +1 row in set (3.505 sec) + +``` + +## keyword + + ORTHOGONAL_BITMAP_INTERSECT,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/orthogonal_bitmap_intersect_count.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/orthogonal_bitmap_intersect_count.md new file mode 100644 index 0000000000..6a033d2fa2 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/orthogonal_bitmap_intersect_count.md @@ -0,0 +1,46 @@ +--- +{ +"title": "orthogonal_bitmap_intersect_count", +"language": "zh-CN" +} +--- + + + +# orthogonal_bitmap_intersect_count +## description +### Syntax + +`BITMAP ORTHOGONAL_BITMAP_INTERSECT_COUNT(bitmap_column, column_to_filter, filter_values)` +求bitmap交集大小的函数, 第一个参数是Bitmap列,第二个参数是用来过滤的维度列,第三个参数是变长参数,含义是过滤维度列的不同取值 + +## example + +``` +mysql> select orthogonal_bitmap_intersect_count(members, tag_group, 1150000, 1150001, 390006) from tag_map where tag_group in ( 1150000, 1150001, 390006); ++-------------------------------------------------------------------------------------+ +| orthogonal_bitmap_intersect_count(`members`, `tag_group`, 1150000, 1150001, 390006) | ++-------------------------------------------------------------------------------------+ +| 0 | ++-------------------------------------------------------------------------------------+ +1 row in set (3.382 sec) +``` + +## keyword + + ORTHOGONAL_BITMAP_INTERSECT_COUNT,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/orthogonal_bitmap_union_count.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/orthogonal_bitmap_union_count.md new file mode 100644 index 0000000000..f964b8312a --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/orthogonal_bitmap_union_count.md @@ -0,0 +1,47 @@ +--- +{ +"title": "orthogonal_bitmap_union_count", +"language": "zh-CN" +} +--- + + + +# orthogonal_bitmap_union_count +## description +### Syntax + +`BITMAP ORTHOGONAL_BITMAP_UNION_COUNT(bitmap_column, column_to_filter, filter_values)` +求bitmap并集大小的函数, 参数类型是bitmap,是待求并集count的列 + + +## example + +``` +mysql> select orthogonal_bitmap_union_count(members) from tag_map where tag_group in ( 1150000, 1150001, 390006); ++------------------------------------------+ +| orthogonal_bitmap_union_count(`members`) | ++------------------------------------------+ +| 286957811 | ++------------------------------------------+ +1 row in set (2.645 sec) +``` + +## keyword + + ORTHOGONAL_BITMAP_UNION_COUNT,BITMAP \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/sub_bitmap.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/sub_bitmap.md new file mode 100644 index 0000000000..211825073c --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/sub_bitmap.md @@ -0,0 +1,62 @@ +--- +{ + "title": "sub_bitmap", + "language": "zh-CN" +} +--- + + + +# sub_bitmap + +## Description + +### Syntax + +`BITMAP SUB_BITMAP(BITMAP src, BIGINT offset, BIGINT cardinality_limit)` + +从 offset 指定位置开始,截取 cardinality_limit 个 bitmap 元素,返回一个 bitmap 子集。 + +## example + +``` +mysql> select bitmap_to_string(sub_bitmap(bitmap_from_string('1,0,1,2,3,1,5'), 0, 3)) value; ++-------+ +| value | ++-------+ +| 0,1,2 | ++-------+ + +mysql> select bitmap_to_string(sub_bitmap(bitmap_from_string('1,0,1,2,3,1,5'), -3, 2)) value; ++-------+ +| value | ++-------+ +| 2,3 | ++-------+ + +mysql> select bitmap_to_string(sub_bitmap(bitmap_from_string('1,0,1,2,3,1,5'), 2, 100)) value; ++-------+ +| value | ++-------+ +| 2,3,5 | ++-------+ +``` + +## keyword + + SUB_BITMAP,BITMAP_SUBSET,BITMAP \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/to_bitmap.md b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/to_bitmap.md new file mode 100644 index 0000000000..022e6d7599 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitmap-functions/to_bitmap.md @@ -0,0 +1,61 @@ +--- +{ + "title": "to_bitmap", + "language": "zh-CN" +} +--- + + + +# to_bitmap +## description +### Syntax + +`BITMAP TO_BITMAP(expr)` + +输入为取值在 0 ~ 18446744073709551615 区间的 unsigned bigint ,输出为包含该元素的bitmap。 +当输入值不在此范围时, 会返回NULL。 +该函数主要用于stream load任务将整型字段导入Doris表的bitmap字段。例如 + +``` +cat data | curl --location-trusted -u user:passwd -T - -H "columns: dt,page,user_id, user_id=to_bitmap(user_id)" http://host:8410/api/test/testDb/_stream_load +``` + +## example + +``` +mysql> select bitmap_count(to_bitmap(10)); ++-----------------------------+ +| bitmap_count(to_bitmap(10)) | ++-----------------------------+ +| 1 | ++-----------------------------+ + +MySQL> select bitmap_to_string(to_bitmap(-1)); ++---------------------------------+ +| bitmap_to_string(to_bitmap(-1)) | ++---------------------------------+ +| NULL | ++---------------------------------+ +``` + +## keyword + + TO_BITMAP,BITMAP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitand.md b/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitand.md new file mode 100644 index 0000000000..c788381183 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitand.md @@ -0,0 +1,57 @@ +--- +{ +"title": "bitand", +"language": "zh-CN" +} +--- + + + +# bitand +## description +### Syntax + +`BITAND(Integer-type lhs, Integer-type rhs)` + +返回两个整数与运算的结果. + +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT + +## example + +``` +mysql> select bitand(3,5) ans; ++------+ +| ans | ++------+ +| 1 | ++------+ + +mysql> select bitand(4,7) ans; ++------+ +| ans | ++------+ +| 4 | ++------+ +``` + +## keyword + + BITAND diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitnot.md b/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitnot.md new file mode 100644 index 0000000000..8ad7911898 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitnot.md @@ -0,0 +1,57 @@ +--- +{ +"title": "bitnot", +"language": "zh-CN" +} +--- + + + +# bitnot +## description +### Syntax + +`BITNOT(Integer-type value)` + +返回一个整数取反运算的结果. + +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT + +## example + +``` +mysql> select bitnot(7) ans; ++------+ +| ans | ++------+ +| -8 | ++------+ + +mysql> select bitxor(-127) ans; ++------+ +| ans | ++------+ +| 126 | ++------+ +``` + +## keyword + + BITNOT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitor.md b/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitor.md new file mode 100644 index 0000000000..c8fb159eb5 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitor.md @@ -0,0 +1,57 @@ +--- +{ +"title": "bitor", +"language": "zh-CN" +} +--- + + + +# bitor +## description +### Syntax + +`BITOR(Integer-type lhs, Integer-type rhs)` + +返回两个整数或运算的结果. + +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT + +## example + +``` +mysql> select bitor(3,5) ans; ++------+ +| ans | ++------+ +| 7 | ++------+ + +mysql> select bitand(4,7) ans; ++------+ +| ans | ++------+ +| 7 | ++------+ +``` + +## keyword + + BITOR diff --git a/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitxor.md b/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitxor.md new file mode 100644 index 0000000000..e3f4655eaa --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/bitwise-functions/bitxor.md @@ -0,0 +1,57 @@ +--- +{ +"title": "bitxor", +"language": "zh-CN" +} +--- + + + +# bitxor +## description +### Syntax + +`BITXOR(Integer-type lhs, Integer-type rhs)` + +返回两个整数异或运算的结果. + +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT + +## example + +``` +mysql> select bitxor(3,5) ans; ++------+ +| ans | ++------+ +| 7 | ++------+ + +mysql> select bitxor(1,7) ans; ++------+ +| ans | ++------+ +| 6 | ++------+ +``` + +## keyword + + BITXOR diff --git a/new-docs/zh-CN/sql-manual/sql-functions/cast.md b/new-docs/zh-CN/sql-manual/sql-functions/cast.md index a2f030de66..45b017382e 100644 --- a/new-docs/zh-CN/sql-manual/sql-functions/cast.md +++ b/new-docs/zh-CN/sql-manual/sql-functions/cast.md @@ -24,4 +24,59 @@ specific language governing permissions and limitations under the License. --> -# CAST \ No newline at end of file +# CAST +## description +### Syntax + +``` +cast (input as type) +``` + +### BIGINT type + +### Syntax(BIGINT) + +``` cast (input as BIGINT) ``` + + +将 input 转成 指定的 type + + +将当前列 input 转换为 BIGINT 类型 + +## example + +1. 转常量,或表中某列 + +``` +mysql> select cast (1 as BIGINT); ++-------------------+ +| CAST(1 AS BIGINT) | ++-------------------+ +| 1 | ++-------------------+ +``` + +2. 转导入的原始数据 + +``` +curl --location-trusted -u root: -T ~/user_data/bigint -H "columns: tmp_k1, k1=cast(tmp_k1 as BIGINT)" http://host:port/api/test/bigint/_stream_load +``` + +*注:在导入中,由于原始类型均为String,将值为浮点的原始数据做 cast的时候数据会被转换成 NULL ,比如 12.0 。Doris目前不会对原始数据做截断。* + +如果想强制将这种类型的原始数据 cast to int 的话。请看下面写法: + +``` +curl --location-trusted -u root: -T ~/user_data/bigint -H "columns: tmp_k1, k1=cast(cast(tmp_k1 as DOUBLE) as BIGINT)" http://host:port/api/test/bigint/_stream_load + +mysql> select cast(cast ("11.2" as double) as bigint); ++----------------------------------------+ +| CAST(CAST('11.2' AS DOUBLE) AS BIGINT) | ++----------------------------------------+ +| 11 | ++----------------------------------------+ +1 row in set (0.00 sec) +``` +## keyword +CAST diff --git a/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/case.md b/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/case.md new file mode 100644 index 0000000000..b1ac6376ae --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/case.md @@ -0,0 +1,72 @@ +--- +{ + "title": "case", + "language": "zh-CN" +} +--- + + + +# case +## description +### Syntax + +``` +CASE expression + WHEN condition1 THEN result1 + [WHEN condition2 THEN result2] + ... + [WHEN conditionN THEN resultN] + [ELSE result] +END +``` +OR +``` +CASE WHEN condition1 THEN result1 + [WHEN condition2 THEN result2] + ... + [WHEN conditionN THEN resultN] + [ELSE result] +END +``` + +将表达式和多个可能的值进行比较,当匹配时返回相应的结果 + +## example + +``` +mysql> select user_id, case user_id when 1 then 'user_id = 1' when 2 then 'user_id = 2' else 'user_id not exist' end test_case from test; ++---------+-------------+ +| user_id | test_case | ++---------+-------------+ +| 1 | user_id = 1 | +| 2 | user_id = 2 | ++---------+-------------+ + +mysql> select user_id, case when user_id = 1 then 'user_id = 1' when user_id = 2 then 'user_id = 2' else 'user_id not exist' end test_case from test; ++---------+-------------+ +| user_id | test_case | ++---------+-------------+ +| 1 | user_id = 1 | +| 2 | user_id = 2 | ++---------+-------------+ +``` +## keyword +CASE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/coalesce.md b/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/coalesce.md new file mode 100644 index 0000000000..5e55515f9a --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/coalesce.md @@ -0,0 +1,47 @@ +--- +{ + "title": "coalesce", + "language": "zh-CN" +} +--- + + + +# coalesce +## description +### Syntax + +`coalesce(expr1, expr2, ...., expr_n))` + +返回参数中的第一个非空表达式(从左向右) + +## example + +``` +mysql> select coalesce(NULL, '1111', '0000'); ++--------------------------------+ +| coalesce(NULL, '1111', '0000') | ++--------------------------------+ +| 1111 | ++--------------------------------+ +``` +## keyword + + COALESCE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/if.md b/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/if.md new file mode 100644 index 0000000000..2f0aea1011 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/if.md @@ -0,0 +1,50 @@ +--- +{ + "title": "if", + "language": "zh-CN" +} +--- + + + +# if +## description +### Syntax + +`if(boolean condition, type valueTrue, type valueFalseOrNull)` + + +如果表达式 condition 成立,返回结果 valueTrue;否则,返回结果 valueFalseOrNull +返回类型: valueTrue 表达式结果的类型 + + +## example + +``` +mysql> select user_id, if(user_id = 1, "true", "false") test_if from test; ++---------+---------+ +| user_id | test_if | ++---------+---------+ +| 1 | true | +| 2 | false | ++---------+---------+ +``` +## keyword +IF diff --git a/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/ifnull.md b/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/ifnull.md new file mode 100644 index 0000000000..1546d81a55 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/ifnull.md @@ -0,0 +1,54 @@ +--- +{ + "title": "ifnull", + "language": "zh-CN" +} +--- + + + +# ifnull +## description +### Syntax + +`ifnull(expr1, expr2)` + + +如果 expr1 的值不为 NULL 则返回 expr1,否则返回 expr2 + +## example + +``` +mysql> select ifnull(1,0); ++--------------+ +| ifnull(1, 0) | ++--------------+ +| 1 | ++--------------+ + +mysql> select ifnull(null,10); ++------------------+ +| ifnull(NULL, 10) | ++------------------+ +| 10 | ++------------------+ +``` +## keyword +IFNULL diff --git a/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/nullif.md b/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/nullif.md new file mode 100644 index 0000000000..d5d66b658d --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/conditional-functions/nullif.md @@ -0,0 +1,61 @@ +--- +{ + "title": "nullif", + "language": "zh-CN" +} +--- + + + +# nullif +## description +### Syntax + +`nullif(expr1, expr2)` + + +如果两个参数相等,则返回NULL。否则返回第一个参数的值。它和以下的 `CASE WHEN` 效果一样 + +``` +CASE + WHEN expr1 = expr2 THEN NULL + ELSE expr1 +END +``` + +## example + +``` +mysql> select nullif(1,1); ++--------------+ +| nullif(1, 1) | ++--------------+ +| NULL | ++--------------+ + +mysql> select nullif(1,0); ++--------------+ +| nullif(1, 0) | ++--------------+ +| 1 | ++--------------+ +``` +## keyword +NULLIF diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/convert_tz.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/convert_tz.md new file mode 100644 index 0000000000..f29bd81993 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/convert_tz.md @@ -0,0 +1,55 @@ +--- +{ + "title": "convert_tz", + "language": "zh-CN" +} +--- + + + +# convert_tz +## description +### Syntax + +`DATETIME CONVERT_TZ(DATETIME dt, VARCHAR from_tz, VARCHAR to_tz)` + +转换datetime值,从 from_tz 给定时区转到 to_tz 给定时区,并返回结果值。 如果参数无效该函数返回NULL。 + +## Example + +``` +mysql> select convert_tz('2019-08-01 13:21:03', 'Asia/Shanghai', 'America/Los_Angeles'); ++---------------------------------------------------------------------------+ +| convert_tz('2019-08-01 13:21:03', 'Asia/Shanghai', 'America/Los_Angeles') | ++---------------------------------------------------------------------------+ +| 2019-07-31 22:21:03 | ++---------------------------------------------------------------------------+ + +mysql> select convert_tz('2019-08-01 13:21:03', '+08:00', 'America/Los_Angeles'); ++--------------------------------------------------------------------+ +| convert_tz('2019-08-01 13:21:03', '+08:00', 'America/Los_Angeles') | ++--------------------------------------------------------------------+ +| 2019-07-31 22:21:03 | ++--------------------------------------------------------------------+ +``` + +## keyword + + CONVERT_TZ diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/curdate.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/curdate.md new file mode 100644 index 0000000000..8dbbce9e93 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/curdate.md @@ -0,0 +1,55 @@ +--- +{ + "title": "curdate,current_date", + "language": "zh-CN" +} +--- + + + +# curdate,current_date +## description +### Syntax + +`DATE CURDATE()` + +获取当前的日期,以DATE类型返回 + +## Examples + +``` +mysql> SELECT CURDATE(); ++------------+ +| CURDATE() | ++------------+ +| 2019-12-20 | ++------------+ + +mysql> SELECT CURDATE() + 0; ++---------------+ +| CURDATE() + 0 | ++---------------+ +| 20191220 | ++---------------+ +``` + +## keyword + + CURDATE,CURRENT_DATE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/current_timestamp.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/current_timestamp.md new file mode 100644 index 0000000000..1a1e99df35 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/current_timestamp.md @@ -0,0 +1,49 @@ +--- +{ + "title": "current_timestamp", + "language": "zh-CN" +} +--- + + + +# current_timestamp +## description +### Syntax + +`DATETIME CURRENT_TIMESTAMP()` + + +获得当前的时间,以Datetime类型返回 + +## example + +``` +mysql> select current_timestamp(); ++---------------------+ +| current_timestamp() | ++---------------------+ +| 2019-05-27 15:59:33 | ++---------------------+ +``` + +## keyword + + CURRENT_TIMESTAMP,CURRENT,TIMESTAMP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/curtime.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/curtime.md new file mode 100644 index 0000000000..19ed78811b --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/curtime.md @@ -0,0 +1,50 @@ +--- +{ + "title": "curtime,current_time", + "language": "zh-CN" +} +--- + + + +# curtime,current_time + +## Syntax + +`TIME CURTIME()` + +## Description + +获得当前的时间,以TIME类型返回 + +## Examples + +``` +mysql> select current_time(); ++----------------+ +| current_time() | ++----------------+ +| 15:25:47 | ++----------------+ +``` + +## keyword + + CURTIME,CURRENT_TIME diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/date_add.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/date_add.md new file mode 100644 index 0000000000..1299bcdd45 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/date_add.md @@ -0,0 +1,55 @@ +--- +{ + "title": "date_add", + "language": "zh-CN" +} +--- + + + +# date_add +## description +### Syntax + +`INT DATE_ADD(DATETIME date,INTERVAL expr type)` + + +向日期添加指定的时间间隔。 + +date 参数是合法的日期表达式。 + +expr 参数是您希望添加的时间间隔。 + +type 参数可以是下列值:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND + +## example + +``` +mysql> select date_add('2010-11-30 23:59:59', INTERVAL 2 DAY); ++-------------------------------------------------+ +| date_add('2010-11-30 23:59:59', INTERVAL 2 DAY) | ++-------------------------------------------------+ +| 2010-12-02 23:59:59 | ++-------------------------------------------------+ +``` + +## keyword + + DATE_ADD,DATE,ADD diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/date_format.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/date_format.md new file mode 100644 index 0000000000..e2621d4a46 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/date_format.md @@ -0,0 +1,168 @@ +--- +{ + "title": "date_format", + "language": "zh-CN" +} +--- + + + +# date_format +## description +### Syntax + +`VARCHAR DATE_FORMAT(DATETIME date, VARCHAR format)` + + +将日期类型按照format的类型转化为字符串, +当前支持最大128字节的字符串,如果返回值长度超过128,则返回NULL + +date 参数是合法的日期。format 规定日期/时间的输出格式。 + +可以使用的格式有: + +%a | 缩写星期名 + +%b | 缩写月名 + +%c | 月,数值 + +%D | 带有英文前缀的月中的天 + +%d | 月的天,数值(00-31) + +%e | 月的天,数值(0-31) + +%f | 微秒 + +%H | 小时 (00-23) + +%h | 小时 (01-12) + +%I | 小时 (01-12) + +%i | 分钟,数值(00-59) + +%j | 年的天 (001-366) + +%k | 小时 (0-23) + +%l | 小时 (1-12) + +%M | 月名 + +%m | 月,数值(00-12) + +%p | AM 或 PM + +%r | 时间,12-小时(hh:mm:ss AM 或 PM) + +%S | 秒(00-59) + +%s | 秒(00-59) + +%T | 时间, 24-小时 (hh:mm:ss) + +%U | 周 (00-53) 星期日是一周的第一天 + +%u | 周 (00-53) 星期一是一周的第一天 + +%V | 周 (01-53) 星期日是一周的第一天,与 %X 使用 + +%v | 周 (01-53) 星期一是一周的第一天,与 %x 使用 + +%W | 星期名 + +%w | 周的天 (0=星期日, 6=星期六) + +%X | 年,其中的星期日是周的第一天,4 位,与 %V 使用 + +%x | 年,其中的星期一是周的第一天,4 位,与 %v 使用 + +%Y | 年,4 位 + +%y | 年,2 位 + +%% | 用于表示 % + +还可以使用三种特殊格式: + +yyyyMMdd + +yyyy-MM-dd + +yyyy-MM-dd HH:mm:ss + +## example + +``` +mysql> select date_format('2009-10-04 22:23:00', '%W %M %Y'); ++------------------------------------------------+ +| date_format('2009-10-04 22:23:00', '%W %M %Y') | ++------------------------------------------------+ +| Sunday October 2009 | ++------------------------------------------------+ + +mysql> select date_format('2007-10-04 22:23:00', '%H:%i:%s'); ++------------------------------------------------+ +| date_format('2007-10-04 22:23:00', '%H:%i:%s') | ++------------------------------------------------+ +| 22:23:00 | ++------------------------------------------------+ + +mysql> select date_format('1900-10-04 22:23:00', '%D %y %a %d %m %b %j'); ++------------------------------------------------------------+ +| date_format('1900-10-04 22:23:00', '%D %y %a %d %m %b %j') | ++------------------------------------------------------------+ +| 4th 00 Thu 04 10 Oct 277 | ++------------------------------------------------------------+ + +mysql> select date_format('1997-10-04 22:23:00', '%H %k %I %r %T %S %w'); ++------------------------------------------------------------+ +| date_format('1997-10-04 22:23:00', '%H %k %I %r %T %S %w') | ++------------------------------------------------------------+ +| 22 22 10 10:23:00 PM 22:23:00 00 6 | ++------------------------------------------------------------+ + +mysql> select date_format('1999-01-01 00:00:00', '%X %V'); ++---------------------------------------------+ +| date_format('1999-01-01 00:00:00', '%X %V') | ++---------------------------------------------+ +| 1998 52 | ++---------------------------------------------+ + +mysql> select date_format('2006-06-01', '%d'); ++------------------------------------------+ +| date_format('2006-06-01 00:00:00', '%d') | ++------------------------------------------+ +| 01 | ++------------------------------------------+ + +mysql> select date_format('2006-06-01', '%%%d'); ++--------------------------------------------+ +| date_format('2006-06-01 00:00:00', '%%%d') | ++--------------------------------------------+ +| %01 | ++--------------------------------------------+ +``` + +## keyword + + DATE_FORMAT,DATE,FORMAT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/date_sub.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/date_sub.md new file mode 100644 index 0000000000..d0d30244ad --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/date_sub.md @@ -0,0 +1,55 @@ +--- +{ + "title": "date_sub", + "language": "zh-CN" +} +--- + + + +# date_sub +## description +### Syntax + +`INT DATE_SUB(DATETIME date,INTERVAL expr type)` + + +从日期减去指定的时间间隔 + +date 参数是合法的日期表达式。 + +expr 参数是您希望添加的时间间隔。 + +type 参数可以是下列值:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND + +## example + +``` +mysql> select date_sub('2010-11-30 23:59:59', INTERVAL 2 DAY); ++-------------------------------------------------+ +| date_sub('2010-11-30 23:59:59', INTERVAL 2 DAY) | ++-------------------------------------------------+ +| 2010-11-28 23:59:59 | ++-------------------------------------------------+ +``` + +## keyword + + DATE_SUB,DATE,SUB diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/datediff.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/datediff.md new file mode 100644 index 0000000000..5d83c5572a --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/datediff.md @@ -0,0 +1,58 @@ +--- +{ + "title": "datediff", + "language": "zh-CN" +} +--- + + + +# datediff +## description +### Syntax + +`DATETIME DATEDIFF(DATETIME expr1,DATETIME expr2)` + + +计算expr1 - expr2,结果精确到天。 + +expr1 和 expr2 参数是合法的日期或日期/时间表达式。 + +注释:只有值的日期部分参与计算。 + +## example + +``` +mysql> select datediff(CAST('2007-12-31 23:59:59' AS DATETIME), CAST('2007-12-30' AS DATETIME)); ++-----------------------------------------------------------------------------------+ +| datediff(CAST('2007-12-31 23:59:59' AS DATETIME), CAST('2007-12-30' AS DATETIME)) | ++-----------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------+ + +mysql> select datediff(CAST('2010-11-30 23:59:59' AS DATETIME), CAST('2010-12-31' AS DATETIME)); ++-----------------------------------------------------------------------------------+ +| datediff(CAST('2010-11-30 23:59:59' AS DATETIME), CAST('2010-12-31' AS DATETIME)) | ++-----------------------------------------------------------------------------------+ +| -31 | ++-----------------------------------------------------------------------------------+ +``` +## keyword +DATEDIFF diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/day.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/day.md new file mode 100644 index 0000000000..f75aa6e571 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/day.md @@ -0,0 +1,49 @@ +--- +{ + "title": "day", + "language": "zh-CN" +} +--- + + + +# day +## description +### Syntax + +`INT DAY(DATETIME date)` + + +获得日期中的天信息,返回值范围从1-31。 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select day('1987-01-31'); ++----------------------------+ +| day('1987-01-31 00:00:00') | ++----------------------------+ +| 31 | ++----------------------------+ +``` +## keyword +DAY diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayname.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayname.md new file mode 100644 index 0000000000..f0905cc624 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayname.md @@ -0,0 +1,50 @@ +--- +{ + "title": "dayname", + "language": "zh-CN" +} +--- + + + +# dayname +## description +### Syntax + +`VARCHAR DAYNAME(DATE)` + + +返回日期对应的日期名字 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select dayname('2007-02-03 00:00:00'); ++--------------------------------+ +| dayname('2007-02-03 00:00:00') | ++--------------------------------+ +| Saturday | ++--------------------------------+ +``` + +## keyword + DAYNAME diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayofmonth.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayofmonth.md new file mode 100644 index 0000000000..b5c9bfd740 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayofmonth.md @@ -0,0 +1,51 @@ +--- +{ + "title": "dayofmonth", + "language": "zh-CN" +} +--- + + + +# dayofmonth +## description +### Syntax + +`INT DAYOFMONTH(DATETIME date)` + + +获得日期中的天信息,返回值范围从1-31。 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select dayofmonth('1987-01-31'); ++-----------------------------------+ +| dayofmonth('1987-01-31 00:00:00') | ++-----------------------------------+ +| 31 | ++-----------------------------------+ +``` + +## keyword + + DAYOFMONTH diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayofweek.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayofweek.md new file mode 100644 index 0000000000..3cddb1395f --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayofweek.md @@ -0,0 +1,58 @@ +--- +{ + "title": "dayofweek", + "language": "zh-CN" +} +--- + + + +# dayofweek +## description +### Syntax + +`INT DAYOFWEEK(DATETIME date)` + + +DAYOFWEEK函数返回日期的工作日索引值,即星期日为1,星期一为2,星期六为7 + +参数为Date或者Datetime类型或者可以cast为Date或者Datetime类型的数字 + +## example + +``` +mysql> select dayofweek('2019-06-25'); ++----------------------------------+ +| dayofweek('2019-06-25 00:00:00') | ++----------------------------------+ +| 3 | ++----------------------------------+ + +mysql> select dayofweek(cast(20190625 as date)); ++-----------------------------------+ +| dayofweek(CAST(20190625 AS DATE)) | ++-----------------------------------+ +| 3 | ++-----------------------------------+ +``` + +## keyword + + DAYOFWEEK diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayofyear.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayofyear.md new file mode 100644 index 0000000000..2538112060 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/dayofyear.md @@ -0,0 +1,51 @@ +--- +{ + "title": "dayofyear", + "language": "zh-CN" +} +--- + + + +# dayofyear +## description +### Syntax + +`INT DAYOFYEAR(DATETIME date)` + + +获得日期中对应当年中的哪一天。 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select dayofyear('2007-02-03 00:00:00'); ++----------------------------------+ +| dayofyear('2007-02-03 00:00:00') | ++----------------------------------+ +| 34 | ++----------------------------------+ +``` + +## keyword + + DAYOFYEAR diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/from_days.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/from_days.md new file mode 100644 index 0000000000..a02fb5005c --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/from_days.md @@ -0,0 +1,49 @@ +--- +{ + "title": "from_days", + "language": "zh-CN" +} +--- + + + +# from_days +## description +### Syntax + +`DATE FROM_DAYS(INT N)` + + +通过距离0000-01-01日的天数计算出哪一天 + +## example + +``` +mysql> select from_days(730669); ++-------------------+ +| from_days(730669) | ++-------------------+ +| 2000-07-03 | ++-------------------+ +``` + +## keyword + + FROM_DAYS,FROM,DAYS diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/from_unixtime.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/from_unixtime.md new file mode 100644 index 0000000000..29a37b75e9 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/from_unixtime.md @@ -0,0 +1,80 @@ +--- +{ + "title": "from_unixtime", + "language": "zh-CN" +} +--- + + + +# from_unixtime +## description +### Syntax + +`DATETIME FROM_UNIXTIME(INT unix_timestamp[, VARCHAR string_format])` + + +将 unix 时间戳转化为对应的 time 格式,返回的格式由 `string_format` 指定 + +支持date_format中的format格式,默认为 %Y-%m-%d %H:%i:%s + +传入的是整形,返回的是字符串类型 + +其余 `string_format` 格式是非法的,返回NULL + +如果给定的时间戳小于 0 或大于 253402271999,则返回 NULL。即时间戳范围是: + +1970-01-01 00:00:00 ~ 9999-12-31 23:59:59 + +## example + +``` +mysql> select from_unixtime(1196440219); ++---------------------------+ +| from_unixtime(1196440219) | ++---------------------------+ +| 2007-12-01 00:30:19 | ++---------------------------+ + +mysql> select from_unixtime(1196440219, 'yyyy-MM-dd HH:mm:ss'); ++--------------------------------------------------+ +| from_unixtime(1196440219, 'yyyy-MM-dd HH:mm:ss') | ++--------------------------------------------------+ +| 2007-12-01 00:30:19 | ++--------------------------------------------------+ + +mysql> select from_unixtime(1196440219, '%Y-%m-%d'); ++-----------------------------------------+ +| from_unixtime(1196440219, '%Y-%m-%d') | ++-----------------------------------------+ +| 2007-12-01 | ++-----------------------------------------+ + +mysql> select from_unixtime(1196440219, '%Y-%m-%d %H:%i:%s'); ++--------------------------------------------------+ +| from_unixtime(1196440219, '%Y-%m-%d %H:%i:%s') | ++--------------------------------------------------+ +| 2007-12-01 00:30:19 | ++--------------------------------------------------+ +``` + +## keyword + + FROM_UNIXTIME,FROM,UNIXTIME diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/hour.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/hour.md new file mode 100644 index 0000000000..a0e5a0bcc5 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/hour.md @@ -0,0 +1,49 @@ +--- +{ + "title": "hour", + "language": "zh-CN" +} +--- + + + +# hour +## description +### Syntax + +`INT HOUR(DATETIME date)` + + +获得日期中的小时的信息,返回值范围从0-23。 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select hour('2018-12-31 23:59:59'); ++-----------------------------+ +| hour('2018-12-31 23:59:59') | ++-----------------------------+ +| 23 | ++-----------------------------+ +``` +## keyword +HOUR diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/makedate.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/makedate.md new file mode 100644 index 0000000000..2d1f94e7b1 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/makedate.md @@ -0,0 +1,46 @@ +--- +{ + "title": "makedate", + "language": "zh-CN" +} +--- + + + +# makedate +## description +### Syntax + +`DATE MAKEDATE(INT year, INT dayofyear)` +返回指定年份和dayofyear构建的日期。dayofyear必须大于0,否则结果为空。 + +## example +``` +mysql> select makedate(2021,1), makedate(2021,100), makedate(2021,400); ++-------------------+---------------------+---------------------+ +| makedate(2021, 1) | makedate(2021, 100) | makedate(2021, 400) | ++-------------------+---------------------+---------------------+ +| 2021-01-01 | 2021-04-10 | 2022-02-04 | ++-------------------+---------------------+---------------------+ +``` + +## keyword + + YEARWEEK diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/minute.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/minute.md new file mode 100644 index 0000000000..18adc66f34 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/minute.md @@ -0,0 +1,49 @@ +--- +{ + "title": "minute", + "language": "zh-CN" +} +--- + + + +# minute +## description +### Syntax + +`INT MINUTE(DATETIME date)` + + +获得日期中的分钟的信息,返回值范围从0-59。 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select minute('2018-12-31 23:59:59'); ++-----------------------------+ +| minute('2018-12-31 23:59:59') | ++-----------------------------+ +| 59 | ++-----------------------------+ +``` +## keyword +MINUTE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/month.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/month.md new file mode 100644 index 0000000000..718857d737 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/month.md @@ -0,0 +1,51 @@ +--- +{ + "title": "month", + "language": "zh-CN" +} +--- + + + +# month +## description +### Syntax + +`INT MONTH(DATETIME date)` + + +返回时间类型中的月份信息,范围是1, 12 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select month('1987-01-01'); ++-----------------------------+ +| month('1987-01-01 00:00:00') | ++-----------------------------+ +| 1 | ++-----------------------------+ +``` + +## keyword + + MONTH diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/monthname.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/monthname.md new file mode 100644 index 0000000000..3ab0684a49 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/monthname.md @@ -0,0 +1,51 @@ +--- +{ + "title": "monthname", + "language": "zh-CN" +} +--- + + + +# monthname +## description +### Syntax + +`VARCHAR MONTHNAME(DATE)` + + +返回日期对应的月份名字 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select monthname('2008-02-03 00:00:00'); ++----------------------------------+ +| monthname('2008-02-03 00:00:00') | ++----------------------------------+ +| February | ++----------------------------------+ +``` + +## keyword + + MONTHNAME diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/now.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/now.md new file mode 100644 index 0000000000..37bd00cdeb --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/now.md @@ -0,0 +1,49 @@ +--- +{ + "title": "now", + "language": "zh-CN" +} +--- + + + +# now +## description +### Syntax + +`DATETIME NOW()` + + +获得当前的时间,以Datetime类型返回 + +## example + +``` +mysql> select now(); ++---------------------+ +| now() | ++---------------------+ +| 2019-05-27 15:58:25 | ++---------------------+ +``` + +## keyword + + NOW diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/second.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/second.md new file mode 100644 index 0000000000..17a0cc035b --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/second.md @@ -0,0 +1,49 @@ +--- +{ + "title": "second", + "language": "zh-CN" +} +--- + + + +# second +## description +### Syntax + +`INT SECOND(DATETIME date)` + + +获得日期中的秒的信息,返回值范围从0-59。 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select second('2018-12-31 23:59:59'); ++-----------------------------+ +| second('2018-12-31 23:59:59') | ++-----------------------------+ +| 59 | ++-----------------------------+ +``` +## keyword +SECOND diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/str_to_date.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/str_to_date.md new file mode 100644 index 0000000000..3102542d01 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/str_to_date.md @@ -0,0 +1,72 @@ +--- +{ + "title": "str_to_date", + "language": "zh-CN" +} +--- + + + +# str_to_date +## description +### Syntax + +`DATETIME STR_TO_DATE(VARCHAR str, VARCHAR format)` + +通过format指定的方式将str转化为DATE类型,如果转化结果不对返回NULL + +支持的format格式与date_format一致 + +## example + +``` +mysql> select str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s'); ++---------------------------------------------------------+ +| str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s') | ++---------------------------------------------------------+ +| 2014-12-21 12:34:56 | ++---------------------------------------------------------+ + +mysql> select str_to_date('2014-12-21 12:34%3A56', '%Y-%m-%d %H:%i%%3A%s'); ++--------------------------------------------------------------+ +| str_to_date('2014-12-21 12:34%3A56', '%Y-%m-%d %H:%i%%3A%s') | ++--------------------------------------------------------------+ +| 2014-12-21 12:34:56 | ++--------------------------------------------------------------+ + +mysql> select str_to_date('200442 Monday', '%X%V %W'); ++-----------------------------------------+ +| str_to_date('200442 Monday', '%X%V %W') | ++-----------------------------------------+ +| 2004-10-18 | ++-----------------------------------------+ + +mysql> select str_to_date("2020-09-01", "%Y-%m-%d %H:%i:%s"); ++------------------------------------------------+ +| str_to_date('2020-09-01', '%Y-%m-%d %H:%i:%s') | ++------------------------------------------------+ +| 2020-09-01 00:00:00 | ++------------------------------------------------+ +1 row in set (0.01 sec) +``` + +## keyword + + STR_TO_DATE,STR,TO,DATE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/time_round.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/time_round.md new file mode 100644 index 0000000000..2e8d142b7c --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/time_round.md @@ -0,0 +1,86 @@ +--- +{ + "title": "time_round", + "language": "zh-CN" +} +--- + + + +# time_round +## description +### Syntax + +`DATETIME TIME_ROUND(DATETIME expr)` + +`DATETIME TIME_ROUND(DATETIME expr, INT period)` + +`DATETIME TIME_ROUND(DATETIME expr, DATETIME origin)` + +`DATETIME TIME_ROUND(DATETIME expr, INT period, DATETIME origin)` + +函数名 `TIME_ROUND` 由两部分组成,每部分由以下可选值组成 +- `TIME`: `SECOND`, `MINUTE`, `HOUR`, `DAY`, `WEEK`, `MONTH`, `YEAR` +- `ROUND`: `FLOOR`, `CEIL` + +返回 `expr` 的上/下界。 + +- `period` 指定每个周期有多少个 `TIME` 单位组成,默认为 `1`。 +- `origin` 指定周期的开始时间,默认为 `1970-01-01T00:00:00`,`WEEK` 的默认开始时间为 `1970-01-04T00:00:00`,即周日。可以比 `expr` 大。 +- 请尽量选择常见 `period`,如 3 `MONTH`,90 `MINUTE` 等,如设置了非常用 `period`,请同时指定 `origin`。 + +## example + +``` + +MySQL> SELECT YEAR_FLOOR('20200202000000'); ++------------------------------+ +| year_floor('20200202000000') | ++------------------------------+ +| 2020-01-01 00:00:00 | ++------------------------------+ + + +MySQL> SELECT MONTH_CEIL(CAST('2020-02-02 13:09:20' AS DATETIME), 3); --quarter ++--------------------------------------------------------+ +| month_ceil(CAST('2020-02-02 13:09:20' AS DATETIME), 3) | ++--------------------------------------------------------+ +| 2020-04-01 00:00:00 | ++--------------------------------------------------------+ + + +MySQL> SELECT WEEK_CEIL('2020-02-02 13:09:20', '2020-01-06'); --monday ++---------------------------------------------------------+ +| week_ceil('2020-02-02 13:09:20', '2020-01-06 00:00:00') | ++---------------------------------------------------------+ +| 2020-02-03 00:00:00 | ++---------------------------------------------------------+ + + +MySQL> SELECT MONTH_CEIL(CAST('2020-02-02 13:09:20' AS DATETIME), 3, CAST('1970-01-09 00:00:00' AS DATETIME)); --next rent day ++-------------------------------------------------------------------------------------------------+ +| month_ceil(CAST('2020-02-02 13:09:20' AS DATETIME), 3, CAST('1970-01-09 00:00:00' AS DATETIME)) | ++-------------------------------------------------------------------------------------------------+ +| 2020-04-09 00:00:00 | ++-------------------------------------------------------------------------------------------------+ + +``` +## keyword +TIME_ROUND diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/timediff.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/timediff.md new file mode 100644 index 0000000000..22a1b74549 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/timediff.md @@ -0,0 +1,65 @@ +--- +{ + "title": "timediff", + "language": "zh-CN" +} +--- + + + +# timediff +## description +### Syntax + +`TIME TIMEDIFF(DATETIME expr1, DATETIME expr2)` + + +TIMEDIFF返回两个DATETIME之间的差值 + +TIMEDIFF函数返回表示为时间值的expr1 - expr2的结果,返回值为TIME类型 + +## example + +``` +mysql> SELECT TIMEDIFF(now(),utc_timestamp()); ++----------------------------------+ +| timediff(now(), utc_timestamp()) | ++----------------------------------+ +| 08:00:00 | ++----------------------------------+ + +mysql> SELECT TIMEDIFF('2019-07-11 16:59:30','2019-07-11 16:59:21'); ++--------------------------------------------------------+ +| timediff('2019-07-11 16:59:30', '2019-07-11 16:59:21') | ++--------------------------------------------------------+ +| 00:00:09 | ++--------------------------------------------------------+ + +mysql> SELECT TIMEDIFF('2019-01-01 00:00:00', NULL); ++---------------------------------------+ +| timediff('2019-01-01 00:00:00', NULL) | ++---------------------------------------+ +| NULL | ++---------------------------------------+ +``` + +## keyword + + TIMEDIFF diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/timestampadd.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/timestampadd.md new file mode 100644 index 0000000000..3a6aba5d53 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/timestampadd.md @@ -0,0 +1,59 @@ +--- +{ + "title": "timestampadd", + "language": "zh-CN" +} +--- + + + +# timestampadd +## description +### Syntax + +`DATETIME TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` + + +将整数表达式间隔添加到日期或日期时间表达式datetime_expr中。 + +interval的单位由unit参数给出,它应该是下列值之一: + +SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR。 + +## example + +``` + +mysql> SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); ++------------------------------------------------+ +| timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | ++------------------------------------------------+ +| 2019-01-02 00:01:00 | ++------------------------------------------------+ + +mysql> SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); ++----------------------------------------------+ +| timestampadd(WEEK, 1, '2019-01-02 00:00:00') | ++----------------------------------------------+ +| 2019-01-09 00:00:00 | ++----------------------------------------------+ +``` +## keyword +TIMESTAMPADD diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/timestampdiff.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/timestampdiff.md new file mode 100644 index 0000000000..d0108633ae --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/timestampdiff.md @@ -0,0 +1,67 @@ +--- +{ + "title": "timestampdiff", + "language": "zh-CN" +} +--- + + + +# timestampdiff +## description +### Syntax + +`INT TIMESTAMPDIFF(unit,DATETIME datetime_expr1, DATETIME datetime_expr2)` + +返回datetime_expr2−datetime_expr1,其中datetime_expr1和datetime_expr2是日期或日期时间表达式。 + +结果(整数)的单位由unit参数给出。interval的单位由unit参数给出,它应该是下列值之一: + +SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR。 + +## example + +``` + +MySQL> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); ++--------------------------------------------------------------------+ +| timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | ++--------------------------------------------------------------------+ +| 3 | ++--------------------------------------------------------------------+ + +MySQL> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); ++-------------------------------------------------------------------+ +| timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | ++-------------------------------------------------------------------+ +| -1 | ++-------------------------------------------------------------------+ + + +MySQL> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); ++---------------------------------------------------------------------+ +| timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | ++---------------------------------------------------------------------+ +| 128885 | ++---------------------------------------------------------------------+ + +``` +## keyword +TIMESTAMPDIFF diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/to_date.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/to_date.md new file mode 100644 index 0000000000..ae07eeda7b --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/to_date.md @@ -0,0 +1,48 @@ +--- +{ + "title": "to_date", + "language": "zh-CN" +} +--- + + + +# to_date +## description +### Syntax + +`DATE TO_DATE(DATETIME)` + +返回 DATETIME 类型中的日期部分。 + +## example + +``` +mysql> select to_date("2020-02-02 00:00:00"); ++--------------------------------+ +| to_date('2020-02-02 00:00:00') | ++--------------------------------+ +| 2020-02-02 | ++--------------------------------+ +``` + +## keyword + + TO_DATE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/to_days.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/to_days.md new file mode 100644 index 0000000000..6498d69c2d --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/to_days.md @@ -0,0 +1,51 @@ +--- +{ + "title": "to_days", + "language": "zh-CN" +} +--- + + + +# to_days +## description +### Syntax + +`INT TO_DAYS(DATETIME date)` + + +返回date距离0000-01-01的天数 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select to_days('2007-10-07'); ++-----------------------+ +| to_days('2007-10-07') | ++-----------------------+ +| 733321 | ++-----------------------+ +``` + +## keyword + + TO_DAYS,TO,DAYS diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/unix_timestamp.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/unix_timestamp.md new file mode 100644 index 0000000000..4c8d9aaeaa --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/unix_timestamp.md @@ -0,0 +1,86 @@ +--- +{ + "title": "unix_timestamp", + "language": "zh-CN" +} +--- + + + +# unix_timestamp +## description +### Syntax + +`INT UNIX_TIMESTAMP(), UNIX_TIMESTAMP(DATETIME date), UNIX_TIMESTAMP(DATETIME date, STRING fmt),` + +将 Date 或者 Datetime 类型转化为 unix 时间戳。 + +如果没有参数,则是将当前的时间转化为时间戳。 + +参数需要是 Date 或者 Datetime 类型。 + +对于在 1970-01-01 00:00:00 之前或 2038-01-19 03:14:07 之后的时间,该函数将返回 0。 + +Format 的格式请参阅 `date_format` 函数的格式说明。 + +该函数受时区影响。 + +## example + +``` +mysql> select unix_timestamp(); ++------------------+ +| unix_timestamp() | ++------------------+ +| 1558589570 | ++------------------+ + +mysql> select unix_timestamp('2007-11-30 10:30:19'); ++---------------------------------------+ +| unix_timestamp('2007-11-30 10:30:19') | ++---------------------------------------+ +| 1196389819 | ++---------------------------------------+ + +mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s'); ++---------------------------------------+ +| unix_timestamp('2007-11-30 10:30-19') | ++---------------------------------------+ +| 1196389819 | ++---------------------------------------+ + +mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s'); ++---------------------------------------+ +| unix_timestamp('2007-11-30 10:30%3A19') | ++---------------------------------------+ +| 1196389819 | ++---------------------------------------+ + +mysql> select unix_timestamp('1969-01-01 00:00:00'); ++---------------------------------------+ +| unix_timestamp('1969-01-01 00:00:00') | ++---------------------------------------+ +| 0 | ++---------------------------------------+ +``` + +## keyword + + UNIX_TIMESTAMP,UNIX,TIMESTAMP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/utc_timestamp.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/utc_timestamp.md new file mode 100644 index 0000000000..2d061e3b60 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/utc_timestamp.md @@ -0,0 +1,53 @@ +--- +{ + "title": "utc_timestamp", + "language": "zh-CN" +} +--- + + + +# utc_timestamp +## description +### Syntax + +`DATETIME UTC_TIMESTAMP()` + + +返回当前UTC日期和时间在 "YYYY-MM-DD HH:MM:SS" 或 + +"YYYYMMDDHHMMSS"格式的一个值 + +根据该函数是否用在字符串或数字语境中 + +## example + +``` +mysql> select utc_timestamp(),utc_timestamp() + 1; ++---------------------+---------------------+ +| utc_timestamp() | utc_timestamp() + 1 | ++---------------------+---------------------+ +| 2019-07-10 12:31:18 | 20190710123119 | ++---------------------+---------------------+ +``` + +## keyword + + UTC_TIMESTAMP,UTC,TIMESTAMP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/week.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/week.md new file mode 100644 index 0000000000..14081a4260 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/week.md @@ -0,0 +1,68 @@ +--- +{ + "title": "week", + "language": "zh-CN" +} +--- + + + +# week +## description +### Syntax + +`INT WEEK(DATE date)` +`INT WEEK(DATE date, INT mode)` + +返回指定日期的星期数。mode的值默认为0。 +参数mode的作用参见下面的表格: +|Mode |星期的第一天 |星期数的范围 |第一个星期的定义 | +|:---|:-------------|:-----------|:--------------------------------------------| +|0 |星期日 |0-53 |这一年中的第一个星期日所在的星期 | +|1 |星期一 |0-53 |这一年的日期所占的天数大于等于4天的第一个星期| +|2 |星期日 |1-53 |这一年中的第一个星期日所在的星期 | +|3 |星期一 |1-53 |这一年的日期所占的天数大于等于4天的第一个星期| +|4 |星期日 |0-53 |这一年的日期所占的天数大于等于4天的第一个星期| +|5 |星期一 |0-53 |这一年中的第一个星期一所在的星期 | +|6 |星期日 |1-53 |这一年的日期所占的天数大于等于4天的第一个星期| +|7 |星期一 |1-53 |这一年中的第一个星期一所在的星期 | + +参数为Date或者Datetime类型 + +## example +``` +mysql> select week('2020-1-1'); ++------------------+ +| week('2020-1-1') | ++------------------+ +| 0 | ++------------------+ +``` +``` +mysql> select week('2020-7-1',1); ++---------------------+ +| week('2020-7-1', 1) | ++---------------------+ +| 27 | ++---------------------+ +``` + +## keyword + WEEK diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/weekday.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/weekday.md new file mode 100644 index 0000000000..e4ec178b96 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/weekday.md @@ -0,0 +1,68 @@ +--- +{ + "title": "weekday", + "language": "zh-CN" +} +--- + + + +# weekday +## Description +### Syntax + +`INT WEEKDAY (DATETIME date)` + + +WEEKDAY函数返回日期的工作日索引值,即星期一为0,星期二为1,星期日为6 + +参数为Date或者Datetime类型或者可以cast为Date或者Datetime类型的数字 + +注意WEEKDAY和DAYOFWEEK的区别: +``` + +-----+-----+-----+-----+-----+-----+-----+ + | Sun | Mon | Tues| Wed | Thur| Fri | Sat | + +-----+-----+-----+-----+-----+-----+-----+ + weekday | 6 | 0 | 1 | 2 | 3 | 4 | 5 | + +-----+-----+-----+-----+-----+-----+-----+ +dayofweek | 1 | 2 | 3 | 4 | 5 | 6 | 7 | + +-----+-----+-----+-----+-----+-----+-----+ +``` + +## example + +``` +mysql> select weekday('2019-06-25'); ++--------------------------------+ +| weekday('2019-06-25 00:00:00') | ++--------------------------------+ +| 1 | ++--------------------------------+ + +mysql> select weekday(cast(20190625 as date)); ++---------------------------------+ +| weekday(CAST(20190625 AS DATE)) | ++---------------------------------+ +| 1 | ++---------------------------------+ +``` + +## keyword +WEEKDAY \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/weekofyear.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/weekofyear.md new file mode 100644 index 0000000000..7d2f71fae1 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/weekofyear.md @@ -0,0 +1,52 @@ +--- +{ + "title": "weekofyear", + "language": "zh-CN" +} +--- + + + +# weekofyear +## description +### Syntax + +`INT WEEKOFYEAR(DATETIME date)` + + + +获得一年中的第几周 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select weekofyear('2008-02-20 00:00:00'); ++-----------------------------------+ +| weekofyear('2008-02-20 00:00:00') | ++-----------------------------------+ +| 8 | ++-----------------------------------+ +``` + +## keyword + + WEEKOFYEAR diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/year.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/year.md new file mode 100644 index 0000000000..4e4c39a7df --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/year.md @@ -0,0 +1,51 @@ +--- +{ + "title": "year", + "language": "zh-CN" +} +--- + + + +# year +## description +### Syntax + +`INT YEAR(DATETIME date)` + + +返回date类型的year部分,范围从1000-9999 + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select year('1987-01-01'); ++-----------------------------+ +| year('1987-01-01 00:00:00') | ++-----------------------------+ +| 1987 | ++-----------------------------+ +``` + +## keyword + + YEAR diff --git a/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/yearweek.md b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/yearweek.md new file mode 100644 index 0000000000..6878b9aee0 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/date-time-functions/yearweek.md @@ -0,0 +1,80 @@ +--- +{ + "title": "yearweek", + "language": "zh-CN" +} +--- + + + +# yearweek +## description +### Syntax + +`INT YEARWEEK(DATE date)` +`INT YEARWEEK(DATE date, INT mode)` + +返回指定日期的年份和星期数。mode的值默认为0。 +当日期所在的星期属于上一年时,返回的是上一年的年份和星期数; +当日期所在的星期属于下一年时,返回的是下一年的年份,星期数为1。 +参数mode的作用参见下面的表格: +|Mode |星期的第一天 |星期数的范围 |第一个星期的定义 | +|:----|:------------|:------------|:--------------------------------------------| +|0 |星期日 |1-53 |这一年中的第一个星期日所在的星期 | +|1 |星期一 |1-53 |这一年的日期所占的天数大于等于4天的第一个星期| +|2 |星期日 |1-53 |这一年中的第一个星期日所在的星期 | +|3 |星期一 |1-53 |这一年的日期所占的天数大于等于4天的第一个星期| +|4 |星期日 |1-53 |这一年的日期所占的天数大于等于4天的第一个星期| +|5 |星期一 |1-53 |这一年中的第一个星期一所在的星期 | +|6 |星期日 |1-53 |这一年的日期所占的天数大于等于4天的第一个星期| +|7 |星期一 |1-53 |这一年中的第一个星期一所在的星期 | + +参数为Date或者Datetime类型 + +## example + +``` +mysql> select yearweek('2021-1-1'); ++----------------------+ +| yearweek('2021-1-1') | ++----------------------+ +| 202052 | ++----------------------+ +``` +``` +mysql> select yearweek('2020-7-1'); ++----------------------+ +| yearweek('2020-7-1') | ++----------------------+ +| 202026 | ++----------------------+ +``` +``` +mysql> select yearweek('2024-12-30',1); ++------------------------------------+ +| yearweek('2024-12-30 00:00:00', 1) | ++------------------------------------+ +| 202501 | ++------------------------------------+ +``` + +## keyword + + YEARWEEK diff --git a/new-docs/zh-CN/sql-manual/sql-functions/digital-masking.md b/new-docs/zh-CN/sql-manual/sql-functions/digital-masking.md index 39b07f7412..f049a30e9e 100644 --- a/new-docs/zh-CN/sql-manual/sql-functions/digital-masking.md +++ b/new-docs/zh-CN/sql-manual/sql-functions/digital-masking.md @@ -24,4 +24,33 @@ specific language governing permissions and limitations under the License. --> -# DIGITAL_MASKING \ No newline at end of file +# DIGITAL_MASKING + +## description + +### Syntax + +``` +digital_masking(digital_number) +``` + +别名函数,原始函数为 `concat(left(id,3),'****',right(id,4))`。 + +将输入的 `digital_number` 进行脱敏处理,返回遮盖脱敏后的结果。`digital_number` 为 `BIGINT` 数据类型。 + +## example + +1. 将手机号码进行脱敏处理 + + ```sql + mysql> select digital_masking(13812345678); + +------------------------------+ + | digital_masking(13812345678) | + +------------------------------+ + | 138****5678 | + +------------------------------+ + ``` + +## keyword + +DIGITAL_MASKING diff --git a/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/aes.md b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/aes.md new file mode 100644 index 0000000000..8f1770772b --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/aes.md @@ -0,0 +1,93 @@ +--- +{ +"title": "AES", +"language": "zh-CN" +} +--- + + + +# AES_ENCRYPT + +## description +Aes 加密函数 +### Syntax + +`VARCHAR AES_ENCRYPT(str,key_str[,init_vector])` + +返回加密后的结果 + +## example + +``` +MySQL > select to_base64(AES_ENCRYPT('text','F3229A0B371ED2D9441B830D21A390C3')); ++--------------------------------+ +| to_base64(aes_encrypt('text')) | ++--------------------------------+ +| wr2JEDVXzL9+2XtRhgIloA== | ++--------------------------------+ +1 row in set (0.010 sec) + +MySQL> set block_encryption_mode="AES_256_CBC"; +Query OK, 0 rows affected (0.006 sec) + +MySQL > select to_base64(AES_ENCRYPT('text','F3229A0B371ED2D9441B830D21A390C3', '0123456789')); ++----------------------------------------------------------------------------------+ +| to_base64(aes_encrypt('text', 'F3229A0B371ED2D9441B830D21A390C3', '0123456789')) | ++----------------------------------------------------------------------------------+ +| mvZT1KJw7N0RJf27aipUpg== | ++----------------------------------------------------------------------------------+ +1 row in set (0.011 sec) +``` + +# AES_DECRYPT + +## description +Aes 解密函数 +### Syntax + +`VARCHAR AES_DECRYPT(str,key_str[,init_vector])` + +返回解密后的结果 + +## example + +``` +MySQL > select AES_DECRYPT(FROM_BASE64('wr2JEDVXzL9+2XtRhgIloA=='),'F3229A0B371ED2D9441B830D21A390C3'); ++------------------------------------------------------+ +| aes_decrypt(from_base64('wr2JEDVXzL9+2XtRhgIloA==')) | ++------------------------------------------------------+ +| text | ++------------------------------------------------------+ +1 row in set (0.012 sec) + +MySQL> set block_encryption_mode="AES_256_CBC"; +Query OK, 0 rows affected (0.006 sec) + +MySQL > select AES_DECRYPT(FROM_BASE64('mvZT1KJw7N0RJf27aipUpg=='),'F3229A0B371ED2D9441B830D21A390C3', '0123456789'); ++--------------------------------------------------------------------------------------------------------+ +| aes_decrypt(from_base64('mvZT1KJw7N0RJf27aipUpg=='), 'F3229A0B371ED2D9441B830D21A390C3', '0123456789') | ++--------------------------------------------------------------------------------------------------------+ +| text | ++--------------------------------------------------------------------------------------------------------+ +1 row in set (0.012 sec) +``` + +## keyword + + AES_ENCRYPT, AES_DECRYPT \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/md5.md b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/md5.md new file mode 100644 index 0000000000..38da45be42 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/md5.md @@ -0,0 +1,47 @@ +--- +{ +"title": "MD5", +"language": "zh-CN" +} +--- + + + +# MD5 + +## description +计算 MD5 128-bit +### Syntax + +`MD5(str)` + +## example + +``` +MySQL [(none)]> select md5("abc"); ++----------------------------------+ +| md5('abc') | ++----------------------------------+ +| 900150983cd24fb0d6963f7d28e17f72 | ++----------------------------------+ +1 row in set (0.013 sec) +``` + +## keyword + + MD5 \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/md5sum.md b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/md5sum.md new file mode 100644 index 0000000000..9374fc46a0 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/md5sum.md @@ -0,0 +1,56 @@ +--- +{ +"title": "MD5SUM", +"language": "zh-CN" +} +--- + + + +# MD5SUM + +## description +计算 多个字符串 MD5 128-bit +### Syntax + +`MD5SUM(str[,str])` + +## example + +``` +MySQL > select md5("abcd"); ++----------------------------------+ +| md5('abcd') | ++----------------------------------+ +| e2fc714c4727ee9395f324cd2e7f331f | ++----------------------------------+ +1 row in set (0.011 sec) + +MySQL > select md5sum("ab","cd"); ++----------------------------------+ +| md5sum('ab', 'cd') | ++----------------------------------+ +| e2fc714c4727ee9395f324cd2e7f331f | ++----------------------------------+ +1 row in set (0.008 sec) + +``` + +## keyword + + MD5SUM \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/sm3.md b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/sm3.md new file mode 100644 index 0000000000..f0efd68f38 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/sm3.md @@ -0,0 +1,47 @@ +--- +{ +"title": "SM3", +"language": "zh-CN" +} +--- + + + +# SM3 + +## description +计算 SM3 256-bit +### Syntax + +`SM3(str)` + +## example + +``` +MySQL > select sm3("abcd"); ++------------------------------------------------------------------+ +| sm3('abcd') | ++------------------------------------------------------------------+ +| 82ec580fe6d36ae4f81cae3c73f4a5b3b5a09c943172dc9053c69fd8e18dca1e | ++------------------------------------------------------------------+ +1 row in set (0.009 sec) +``` + +## keyword + + SM3 \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/sm3sum.md b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/sm3sum.md new file mode 100644 index 0000000000..5f0f9712da --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/sm3sum.md @@ -0,0 +1,56 @@ +--- +{ +"title": "SM3SUM", +"language": "zh-CN" +} +--- + + + +# SM3SUM + +## description +计算 多个字符串 SM3 256-bit +### Syntax + +`SM3SUM(str[,str])` + +## example + +``` +MySQL > select sm3("abcd"); ++------------------------------------------------------------------+ +| sm3('abcd') | ++------------------------------------------------------------------+ +| 82ec580fe6d36ae4f81cae3c73f4a5b3b5a09c943172dc9053c69fd8e18dca1e | ++------------------------------------------------------------------+ +1 row in set (0.009 sec) + +MySQL > select sm3sum("ab","cd"); ++------------------------------------------------------------------+ +| sm3sum('ab', 'cd') | ++------------------------------------------------------------------+ +| 82ec580fe6d36ae4f81cae3c73f4a5b3b5a09c943172dc9053c69fd8e18dca1e | ++------------------------------------------------------------------+ +1 row in set (0.009 sec) + +``` + +## keyword + + SM3SUM \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/sm4.md b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/sm4.md new file mode 100644 index 0000000000..35b6575fe4 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/encrypt-digest-functions/sm4.md @@ -0,0 +1,93 @@ +--- +{ +"title": "SM4", +"language": "zh-CN" +} +--- + + + +# SM4_ENCRYPT + +## description +SM4 加密函数 +### Syntax + +`VARCHAR SM4_ENCRYPT(str,key_str[,init_vector])` + +返回加密后的结果 + +## example + +``` +MySQL > select TO_BASE64(SM4_ENCRYPT('text','F3229A0B371ED2D9441B830D21A390C3')); ++--------------------------------+ +| to_base64(sm4_encrypt('text')) | ++--------------------------------+ +| aDjwRflBrDjhBZIOFNw3Tg== | ++--------------------------------+ +1 row in set (0.010 sec) + +MySQL > set block_encryption_mode="SM4_128_CBC"; +Query OK, 0 rows affected (0.001 sec) + +MySQL > select to_base64(SM4_ENCRYPT('text','F3229A0B371ED2D9441B830D21A390C3', '0123456789')); ++----------------------------------------------------------------------------------+ +| to_base64(sm4_encrypt('text', 'F3229A0B371ED2D9441B830D21A390C3', '0123456789')) | ++----------------------------------------------------------------------------------+ +| G7yqOKfEyxdagboz6Qf01A== | ++----------------------------------------------------------------------------------+ +1 row in set (0.014 sec) +``` + +# SM4_DECRYPT + +## description +Aes 解密函数 +### Syntax + +`VARCHAR AES_DECRYPT(str,key_str[,init_vector])` + +返回解密后的结果 + +## example + +``` +MySQL [(none)]> select SM4_DECRYPT(FROM_BASE64('aDjwRflBrDjhBZIOFNw3Tg=='),'F3229A0B371ED2D9441B830D21A390C3'); ++------------------------------------------------------+ +| sm4_decrypt(from_base64('aDjwRflBrDjhBZIOFNw3Tg==')) | ++------------------------------------------------------+ +| text | ++------------------------------------------------------+ +1 row in set (0.009 sec) + +MySQL> set block_encryption_mode="SM4_128_CBC"; +Query OK, 0 rows affected (0.006 sec) + +MySQL > select SM4_DECRYPT(FROM_BASE64('G7yqOKfEyxdagboz6Qf01A=='),'F3229A0B371ED2D9441B830D21A390C3', '0123456789'); ++--------------------------------------------------------------------------------------------------------+ +| sm4_decrypt(from_base64('G7yqOKfEyxdagboz6Qf01A=='), 'F3229A0B371ED2D9441B830D21A390C3', '0123456789') | ++--------------------------------------------------------------------------------------------------------+ +| text | ++--------------------------------------------------------------------------------------------------------+ +1 row in set (0.012 sec) +``` + +## keyword + + SM4_ENCRYPT, SM4_DECRYPT \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/hash-functions/murmur_hash3_32.md b/new-docs/zh-CN/sql-manual/sql-functions/hash-functions/murmur_hash3_32.md new file mode 100644 index 0000000000..f1f237255a --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/hash-functions/murmur_hash3_32.md @@ -0,0 +1,61 @@ +--- +{ + "title": "murmur_hash3_32", + "language": "zh-CN" +} +--- + + + +# murmur_hash3_32 + +## description +### Syntax + +`INT MURMUR_HASH3_32(VARCHAR input, ...)` + +返回输入字符串的32位murmur3 hash值 + +## example + +``` +mysql> select murmur_hash3_32(null); ++-----------------------+ +| murmur_hash3_32(NULL) | ++-----------------------+ +| NULL | ++-----------------------+ + +mysql> select murmur_hash3_32("hello"); ++--------------------------+ +| murmur_hash3_32('hello') | ++--------------------------+ +| 1321743225 | ++--------------------------+ + +mysql> select murmur_hash3_32("hello", "world"); ++-----------------------------------+ +| murmur_hash3_32('hello', 'world') | ++-----------------------------------+ +| 984713481 | ++-----------------------------------+ +``` + +## keyword + + MURMUR_HASH3_32,HASH diff --git a/new-docs/zh-CN/sql-manual/sql-functions/json-functions/get_json_double.md b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/get_json_double.md new file mode 100644 index 0000000000..782bdc8eba --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/get_json_double.md @@ -0,0 +1,74 @@ +--- +{ + "title": "get_json_double", + "language": "zh-CN" +} +--- + + + +# get_json_double +## description +### Syntax + +`DOUBLE get_json_double(VARCHAR json_str, VARCHAR json_path)` + + +解析并获取 json 字符串内指定路径的浮点型内容。 +其中 json_path 必须以 $ 符号作为开头,使用 . 作为路径分割符。如果路径中包含 . ,则可以使用双引号包围。 +使用 [ ] 表示数组下标,从 0 开始。 +path 的内容不能包含 ", [ 和 ]。 +如果 json_string 格式不对,或 json_path 格式不对,或无法找到匹配项,则返回 NULL。 + +## example + +1. 获取 key 为 "k1" 的 value + +``` +mysql> SELECT get_json_double('{"k1":1.3, "k2":"2"}', "$.k1"); ++-------------------------------------------------+ +| get_json_double('{"k1":1.3, "k2":"2"}', '$.k1') | ++-------------------------------------------------+ +| 1.3 | ++-------------------------------------------------+ +``` + +2. 获取 key 为 "my.key" 的数组中第二个元素 + +``` +mysql> SELECT get_json_double('{"k1":"v1", "my.key":[1.1, 2.2, 3.3]}', '$."my.key"[1]'); ++---------------------------------------------------------------------------+ +| get_json_double('{"k1":"v1", "my.key":[1.1, 2.2, 3.3]}', '$."my.key"[1]') | ++---------------------------------------------------------------------------+ +| 2.2 | ++---------------------------------------------------------------------------+ +``` + +3. 获取二级路径为 k1.key -> k2 的数组中,第一个元素 +``` +mysql> SELECT get_json_double('{"k1.key":{"k2":[1.1, 2.2]}}', '$."k1.key".k2[0]'); ++---------------------------------------------------------------------+ +| get_json_double('{"k1.key":{"k2":[1.1, 2.2]}}', '$."k1.key".k2[0]') | ++---------------------------------------------------------------------+ +| 1.1 | ++---------------------------------------------------------------------+ +``` +## keyword +GET_JSON_DOUBLE,GET,JSON,DOUBLE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/json-functions/get_json_int.md b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/get_json_int.md new file mode 100644 index 0000000000..7b1ac67a44 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/get_json_int.md @@ -0,0 +1,74 @@ +--- +{ + "title": "get_json_int", + "language": "zh-CN" +} +--- + + + +# get_json_int +## description +### Syntax + +`INT get_json_int(VARCHAR json_str, VARCHAR json_path)` + + +解析并获取 json 字符串内指定路径的整型内容。 +其中 json_path 必须以 $ 符号作为开头,使用 . 作为路径分割符。如果路径中包含 . ,则可以使用双引号包围。 +使用 [ ] 表示数组下标,从 0 开始。 +path 的内容不能包含 ", [ 和 ]。 +如果 json_string 格式不对,或 json_path 格式不对,或无法找到匹配项,则返回 NULL。 + +## example + +1. 获取 key 为 "k1" 的 value + +``` +mysql> SELECT get_json_int('{"k1":1, "k2":"2"}', "$.k1"); ++--------------------------------------------+ +| get_json_int('{"k1":1, "k2":"2"}', '$.k1') | ++--------------------------------------------+ +| 1 | ++--------------------------------------------+ +``` + +2. 获取 key 为 "my.key" 的数组中第二个元素 + +``` +mysql> SELECT get_json_int('{"k1":"v1", "my.key":[1, 2, 3]}', '$."my.key"[1]'); ++------------------------------------------------------------------+ +| get_json_int('{"k1":"v1", "my.key":[1, 2, 3]}', '$."my.key"[1]') | ++------------------------------------------------------------------+ +| 2 | ++------------------------------------------------------------------+ +``` + +3. 获取二级路径为 k1.key -> k2 的数组中,第一个元素 +``` +mysql> SELECT get_json_int('{"k1.key":{"k2":[1, 2]}}', '$."k1.key".k2[0]'); ++--------------------------------------------------------------+ +| get_json_int('{"k1.key":{"k2":[1, 2]}}', '$."k1.key".k2[0]') | ++--------------------------------------------------------------+ +| 1 | ++--------------------------------------------------------------+ +``` +## keyword +GET_JSON_INT,GET,JSON,INT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/json-functions/get_json_string.md b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/get_json_string.md new file mode 100644 index 0000000000..9311a77ea7 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/get_json_string.md @@ -0,0 +1,84 @@ +--- +{ + "title": "get_json_string", + "language": "zh-CN" +} +--- + + + +# get_json_string +## description +### Syntax + +`VARCHAR get_json_string(VARCHAR json_str, VARCHAR json_path)` + + +解析并获取 json 字符串内指定路径的字符串内容。 +其中 json_path 必须以 $ 符号作为开头,使用 . 作为路径分割符。如果路径中包含 . ,则可以使用双引号包围。 +使用 [ ] 表示数组下标,从 0 开始。 +path 的内容不能包含 ", [ 和 ]。 +如果 json_string 格式不对,或 json_path 格式不对,或无法找到匹配项,则返回 NULL。 + +## example + +1. 获取 key 为 "k1" 的 value + +``` +mysql> SELECT get_json_string('{"k1":"v1", "k2":"v2"}', "$.k1"); ++---------------------------------------------------+ +| get_json_string('{"k1":"v1", "k2":"v2"}', '$.k1') | ++---------------------------------------------------+ +| v1 | ++---------------------------------------------------+ +``` + +2. 获取 key 为 "my.key" 的数组中第二个元素 + +``` +mysql> SELECT get_json_string('{"k1":"v1", "my.key":["e1", "e2", "e3"]}', '$."my.key"[1]'); ++------------------------------------------------------------------------------+ +| get_json_string('{"k1":"v1", "my.key":["e1", "e2", "e3"]}', '$."my.key"[1]') | ++------------------------------------------------------------------------------+ +| e2 | ++------------------------------------------------------------------------------+ +``` + +3. 获取二级路径为 k1.key -> k2 的数组中,第一个元素 +``` +mysql> SELECT get_json_string('{"k1.key":{"k2":["v1", "v2"]}}', '$."k1.key".k2[0]'); ++-----------------------------------------------------------------------+ +| get_json_string('{"k1.key":{"k2":["v1", "v2"]}}', '$."k1.key".k2[0]') | ++-----------------------------------------------------------------------+ +| v1 | ++-----------------------------------------------------------------------+ +``` + +4. 获取数组中,key 为 "k1" 的所有 value +``` +mysql> SELECT get_json_string('[{"k1":"v1"}, {"k2":"v2"}, {"k1":"v3"}, {"k1":"v4"}]', '$.k1'); ++---------------------------------------------------------------------------------+ +| get_json_string('[{"k1":"v1"}, {"k2":"v2"}, {"k1":"v3"}, {"k1":"v4"}]', '$.k1') | ++---------------------------------------------------------------------------------+ +| ["v1","v3","v4"] | ++---------------------------------------------------------------------------------+ +``` +## keyword +GET_JSON_STRING,GET,JSON,STRING diff --git a/new-docs/zh-CN/sql-manual/sql-functions/json-functions/json_array.md b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/json_array.md new file mode 100644 index 0000000000..ff6a622cf3 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/json_array.md @@ -0,0 +1,70 @@ +--- +{ + "title": "json_array", + "language": "zh-CN" +} +--- + + + +# json_array +## description +### Syntax + +`VARCHAR json_array(VARCHAR,...)` + + +生成一个包含指定元素的json数组,未指定时返回空数组 + +## example + +``` +MySQL> select json_array(); ++--------------+ +| json_array() | ++--------------+ +| [] | ++--------------+ + +MySQL> select json_array(null); ++--------------------+ +| json_array('NULL') | ++--------------------+ +| [NULL] | ++--------------------+ + + +MySQL> SELECT json_array(1, "abc", NULL, TRUE, CURTIME()); ++-----------------------------------------------+ +| json_array(1, 'abc', 'NULL', TRUE, curtime()) | ++-----------------------------------------------+ +| [1, "abc", NULL, TRUE, "10:41:15"] | ++-----------------------------------------------+ + + +MySQL> select json_array("a", null, "c"); ++------------------------------+ +| json_array('a', 'NULL', 'c') | ++------------------------------+ +| ["a", NULL, "c"] | ++------------------------------+ +``` +## keyword +json_array diff --git a/new-docs/zh-CN/sql-manual/sql-functions/json-functions/json_object.md b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/json_object.md new file mode 100644 index 0000000000..0f3b1fe8a6 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/json_object.md @@ -0,0 +1,70 @@ +--- +{ + "title": "json_object", + "language": "zh-CN" +} +--- + + + +# json_object +## description +### Syntax + +`VARCHAR json_object(VARCHAR,...)` + + +生成一个包含指定Key-Value对的json object, 当Key值为NULL或者传入参数为奇数个时,返回异常错误 + +## example + +``` +MySQL> select json_object(); ++---------------+ +| json_object() | ++---------------+ +| {} | ++---------------+ + +MySQL> select json_object('time',curtime()); ++--------------------------------+ +| json_object('time', curtime()) | ++--------------------------------+ +| {"time": "10:49:18"} | ++--------------------------------+ + + +MySQL> SELECT json_object('id', 87, 'name', 'carrot'); ++-----------------------------------------+ +| json_object('id', 87, 'name', 'carrot') | ++-----------------------------------------+ +| {"id": 87, "name": "carrot"} | ++-----------------------------------------+ + + +MySQL> select json_object('username',null); ++---------------------------------+ +| json_object('username', 'NULL') | ++---------------------------------+ +| {"username": NULL} | ++---------------------------------+ +``` +## keyword +json_object diff --git a/new-docs/zh-CN/sql-manual/sql-functions/json-functions/json_quote.md b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/json_quote.md new file mode 100644 index 0000000000..67ed605b60 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/json-functions/json_quote.md @@ -0,0 +1,70 @@ +--- +{ + "title": "json_quote", + "language": "zh-CN" +} +--- + + + +# json_quote +## description +### Syntax + +`VARCHAR json_quote(VARCHAR)` + + +将json_value用双引号(")括起来,跳过其中包含的特殊转义字符 + +## example + +``` +MySQL> SELECT json_quote('null'), json_quote('"null"'); ++--------------------+----------------------+ +| json_quote('null') | json_quote('"null"') | ++--------------------+----------------------+ +| "null" | "\"null\"" | ++--------------------+----------------------+ + + +MySQL> SELECT json_quote('[1, 2, 3]'); ++-------------------------+ +| json_quote('[1, 2, 3]') | ++-------------------------+ +| "[1, 2, 3]" | ++-------------------------+ + + +MySQL> SELECT json_quote(null); ++------------------+ +| json_quote(null) | ++------------------+ +| NULL | ++------------------+ + +MySQL> select json_quote("\n\b\r\t"); ++------------------------+ +| json_quote('\n\b\r\t') | ++------------------------+ +| "\n\b\r\t" | ++------------------------+ +``` +## keyword +json_quote diff --git a/new-docs/zh-CN/sql-manual/sql-functions/math-functions/conv.md b/new-docs/zh-CN/sql-manual/sql-functions/math-functions/conv.md new file mode 100644 index 0000000000..280228ec89 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/math-functions/conv.md @@ -0,0 +1,60 @@ +--- +{ + "title": "conv", + "language": "zh-CN" +} +--- + + + +# conv + +## description +### Syntax + +`VARCHAR CONV(VARCHAR input, TINYINT from_base, TINYINT to_base)` +`VARCHAR CONV(BIGINT input, TINYINT from_base, TINYINT to_base)` +对输入的数字进行进制转换,输入的进制范围应该在`[2,36]`以内。 + +## example + +``` +MySQL [test]> SELECT CONV(15,10,2); ++-----------------+ +| conv(15, 10, 2) | ++-----------------+ +| 1111 | ++-----------------+ + +MySQL [test]> SELECT CONV('ff',16,10); ++--------------------+ +| conv('ff', 16, 10) | ++--------------------+ +| 255 | ++--------------------+ + +MySQL [test]> SELECT CONV(230,10,16); ++-------------------+ +| conv(230, 10, 16) | ++-------------------+ +| E6 | ++-------------------+ +``` + +## keyword + CONV diff --git a/new-docs/zh-CN/sql-manual/sql-functions/math-functions/pmod.md b/new-docs/zh-CN/sql-manual/sql-functions/math-functions/pmod.md new file mode 100644 index 0000000000..d97968b956 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/math-functions/pmod.md @@ -0,0 +1,53 @@ +--- +{ + "title": "pmod", + "language": "zh-CN" +} +--- + + + +# pmod + +## description +### Syntax + +`BIGINT PMOD(BIGINT x, BIGINT y)` +`DOUBLE PMOD(DOUBLE x, DOUBLE y)` +返回在模系下`x mod y`的最小正数解. +具体地来说, 返回 `(x%y+y)%y`. + +## example + +``` +MySQL [test]> SELECT PMOD(13,5); ++-------------+ +| pmod(13, 5) | ++-------------+ +| 3 | ++-------------+ +MySQL [test]> SELECT PMOD(-13,5); ++-------------+ +| pmod(-13, 5) | ++-------------+ +| 2 | ++-------------+ +``` + +## keyword + PMOD diff --git a/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_astext.md b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_astext.md new file mode 100644 index 0000000000..1b187507af --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_astext.md @@ -0,0 +1,47 @@ +--- +{ + "title": "`ST_AsText`,`ST_AsWKT`", + "language": "zh-CN" +} +--- + + + +# `ST_AsText`,`ST_AsWKT` +## description +### Syntax + +`VARCHAR ST_AsText(GEOMETRY geo)` + + +将一个几何图形转化为WKT(Well Known Text)的表示形式 + +## example + +``` +mysql> SELECT ST_AsText(ST_Point(24.7, 56.7)); ++---------------------------------+ +| st_astext(st_point(24.7, 56.7)) | ++---------------------------------+ +| POINT (24.7 56.7) | ++---------------------------------+ +``` +## keyword +ST_ASTEXT,ST_ASWKT,ST,ASTEXT,ASWKT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_circle.md b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_circle.md new file mode 100644 index 0000000000..8c8ac1efb8 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_circle.md @@ -0,0 +1,48 @@ +--- +{ + "title": "`ST_Circle`", + "language": "zh-CN" +} +--- + + + +# `ST_Circle` +## description +### Syntax + +`GEOMETRY ST_Circle(DOUBLE center_lng, DOUBLE center_lat, DOUBLE radius)` + + +将一个WKT(Well Known Text)转化为地球球面上的一个圆。其中`center_lng`表示的圆心的经度, +`center_lat`表示的是圆心的纬度,`radius`表示的是圆的半径,单位是米,最大支持9999999 + +## example + +``` +mysql> SELECT ST_AsText(ST_Circle(111, 64, 10000)); ++--------------------------------------------+ +| st_astext(st_circle(111.0, 64.0, 10000.0)) | ++--------------------------------------------+ +| CIRCLE ((111 64), 10000) | ++--------------------------------------------+ +``` +## keyword +ST_CIRCLE,ST,CIRCLE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_contains.md b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_contains.md new file mode 100644 index 0000000000..393cb9a6b1 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_contains.md @@ -0,0 +1,54 @@ +--- +{ + "title": "`ST_Contains`", + "language": "zh-CN" +} +--- + + + +# `ST_Contains` +## description +### Syntax + +`BOOL ST_Contains(GEOMETRY shape1, GEOMETRY shape2)` + + +判断几何图形shape1是否完全能够包含几何图形shape2 + +## example + +``` +mysql> SELECT ST_Contains(ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"), ST_Point(5, 5)); ++----------------------------------------------------------------------------------------+ +| st_contains(st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'), st_point(5.0, 5.0)) | ++----------------------------------------------------------------------------------------+ +| 1 | ++----------------------------------------------------------------------------------------+ + +mysql> SELECT ST_Contains(ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"), ST_Point(50, 50)); ++------------------------------------------------------------------------------------------+ +| st_contains(st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'), st_point(50.0, 50.0)) | ++------------------------------------------------------------------------------------------+ +| 0 | ++------------------------------------------------------------------------------------------+ +``` +## keyword +ST_CONTAINS,ST,CONTAINS diff --git a/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_distance_sphere.md b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_distance_sphere.md new file mode 100644 index 0000000000..a55072982e --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_distance_sphere.md @@ -0,0 +1,47 @@ +--- +{ + "title": "`ST_Distance_Sphere`", + "language": "zh-CN" +} +--- + + + +# `ST_Distance_Sphere` +## description +### Syntax + +`DOUBLE ST_Distance_Sphere(DOUBLE x_lng, DOUBLE x_lat, DOUBLE y_lng, DOUBLE x_lat)` + + +计算地球两点之间的球面距离,单位为 米。传入的参数分别为X点的经度,X点的纬度,Y点的经度,Y点的纬度。 + +## example + +``` +mysql> select st_distance_sphere(116.35620117, 39.939093, 116.4274406433, 39.9020987219); ++----------------------------------------------------------------------------+ +| st_distance_sphere(116.35620117, 39.939093, 116.4274406433, 39.9020987219) | ++----------------------------------------------------------------------------+ +| 7336.9135549995917 | ++----------------------------------------------------------------------------+ +``` +## keyword +ST_DISTANCE_SPHERE,ST,DISTANCE,SPHERE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_geometryfromtext.md b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_geometryfromtext.md new file mode 100644 index 0000000000..802ca72af1 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_geometryfromtext.md @@ -0,0 +1,47 @@ +--- +{ + "title": "`ST_GeometryFromText`,`ST_GeomFromText`", + "language": "zh-CN" +} +--- + + + +# `ST_GeometryFromText`,`ST_GeomFromText` +## description +### Syntax + +`GEOMETRY ST_GeometryFromText(VARCHAR wkt)` + + +将一个WKT(Well Known Text)转化为对应的内存的几何形式 + +## example + +``` +mysql> SELECT ST_AsText(ST_GeometryFromText("LINESTRING (1 1, 2 2)")); ++---------------------------------------------------------+ +| st_astext(st_geometryfromtext('LINESTRING (1 1, 2 2)')) | ++---------------------------------------------------------+ +| LINESTRING (1 1, 2 2) | ++---------------------------------------------------------+ +``` +## keyword +ST_GEOMETRYFROMTEXT,ST_GEOMFROMTEXT,ST,GEOMETRYFROMTEXT,GEOMFROMTEXT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_linefromtext.md b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_linefromtext.md new file mode 100644 index 0000000000..a135f14e5f --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_linefromtext.md @@ -0,0 +1,47 @@ +--- +{ + "title": "`ST_LineFromText`,`ST_LineStringFromText`", + "language": "zh-CN" +} +--- + + + +# `ST_LineFromText`,`ST_LineStringFromText` +## description +### Syntax + +`GEOMETRY ST_LineFromText(VARCHAR wkt)` + + +将一个WKT(Well Known Text)转化为一个Line形式的内存表现形式 + +## example + +``` +mysql> SELECT ST_AsText(ST_LineFromText("LINESTRING (1 1, 2 2)")); ++---------------------------------------------------------+ +| st_astext(st_geometryfromtext('LINESTRING (1 1, 2 2)')) | ++---------------------------------------------------------+ +| LINESTRING (1 1, 2 2) | ++---------------------------------------------------------+ +``` +## keyword +ST_LINEFROMTEXT,ST_LINESTRINGFROMTEXT,ST,LINEFROMTEXT,LINESTRINGFROMTEXT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_point.md b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_point.md new file mode 100644 index 0000000000..3aa9efb1fb --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_point.md @@ -0,0 +1,48 @@ +--- +{ + "title": "`ST_Point`", + "language": "zh-CN" +} +--- + + + +# `ST_Point` +## description +### Syntax + +`POINT ST_Point(DOUBLE x, DOUBLE y)` + + +通过给定的X坐标值,Y坐标值返回对应的Point。 +当前这个值只是在球面集合上有意义,X/Y对应的是经度/纬度(longitude/latitude);ps:直接select ST_Point()会卡主,慎重!!! + +## example + +``` +mysql> SELECT ST_AsText(ST_Point(24.7, 56.7)); ++---------------------------------+ +| st_astext(st_point(24.7, 56.7)) | ++---------------------------------+ +| POINT (24.7 56.7) | ++---------------------------------+ +``` +## keyword +ST_POINT,ST,POINT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_polygon.md b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_polygon.md new file mode 100644 index 0000000000..eb6ab99a75 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_polygon.md @@ -0,0 +1,47 @@ +--- +{ + "title": "`ST_Polygon`,`ST_PolyFromText`,`ST_PolygonFromText`", + "language": "zh-CN" +} +--- + + + +# `ST_Polygon`,`ST_PolyFromText`,`ST_PolygonFromText` +## description +### Syntax + +`GEOMETRY ST_Polygon(VARCHAR wkt)` + + +将一个WKT(Well Known Text)转化为对应的多边形内存形式 + +## example + +``` +mysql> SELECT ST_AsText(ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); ++------------------------------------------------------------------+ +| st_astext(st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++------------------------------------------------------------------+ +| POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0)) | ++------------------------------------------------------------------+ +``` +## keyword +ST_POLYGON,ST_POLYFROMTEXT,ST_POLYGONFROMTEXT,ST,POLYGON,POLYFROMTEXT,POLYGONFROMTEXT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_x.md b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_x.md new file mode 100644 index 0000000000..971085f270 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_x.md @@ -0,0 +1,47 @@ +--- +{ + "title": "`ST_X`", + "language": "zh-CN" +} +--- + + + +# `ST_X` +## description +### Syntax + +`DOUBLE ST_X(POINT point)` + + +当point是一个合法的POINT类型时,返回对应的X坐标值 + +## example + +``` +mysql> SELECT ST_X(ST_Point(24.7, 56.7)); ++----------------------------+ +| st_x(st_point(24.7, 56.7)) | ++----------------------------+ +| 24.7 | ++----------------------------+ +``` +## keyword +ST_X,ST,X diff --git a/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_y.md b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_y.md new file mode 100644 index 0000000000..fda4b4777d --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/spatial-functions/st_y.md @@ -0,0 +1,47 @@ +--- +{ + "title": "`ST_Y`", + "language": "zh-CN" +} +--- + + + +# `ST_Y` +## description +### Syntax + +`DOUBLE ST_Y(POINT point)` + + +当point是一个合法的POINT类型时,返回对应的Y坐标值 + +## example + +``` +mysql> SELECT ST_Y(ST_Point(24.7, 56.7)); ++----------------------------+ +| st_y(st_point(24.7, 56.7)) | ++----------------------------+ +| 56.7 | ++----------------------------+ +``` +## keyword +ST_Y,ST,Y diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/append_trailing_char_if_absent.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/append_trailing_char_if_absent.md new file mode 100644 index 0000000000..3250d00c9f --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/append_trailing_char_if_absent.md @@ -0,0 +1,60 @@ +--- +{ + "title": "append_trailing_char_if_absent", + "language": "zh-CN" +} +--- + + + +# append_trailing_char_if_absent + +## description + +### Syntax + +`VARCHAR append_trailing_char_if_absent(VARCHAR str, VARCHAR trailing_char)` + +如果 str 字符串非空并且末尾不包含 trailing_char 字符,则将 trailing_char 字符附加到末尾。 +trailing_char 只能包含一个字符,如果包含多个字符,将返回NULL + +## example + +``` +MySQL [test]> select append_trailing_char_if_absent('a','c'); ++------------------------------------------+ +| append_trailing_char_if_absent('a', 'c') | ++------------------------------------------+ +| ac | ++------------------------------------------+ +1 row in set (0.02 sec) + +MySQL [test]> select append_trailing_char_if_absent('ac','c'); ++-------------------------------------------+ +| append_trailing_char_if_absent('ac', 'c') | ++-------------------------------------------+ +| ac | ++-------------------------------------------+ +1 row in set (0.00 sec) +``` + +## keyword + +APPEND_TRAILING_CHAR_IF_ABSENT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/ascii.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/ascii.md new file mode 100644 index 0000000000..73f2dc8bd0 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/ascii.md @@ -0,0 +1,54 @@ +--- +{ + "title": "ascii", + "language": "zh-CN" +} +--- + + + +# ascii +## description +### Syntax + +`INT ascii(VARCHAR str)` + + +返回字符串第一个字符对应的 ascii 码 + +## example + +``` +mysql> select ascii('1'); ++------------+ +| ascii('1') | ++------------+ +| 49 | ++------------+ + +mysql> select ascii('234'); ++--------------+ +| ascii('234') | ++--------------+ +| 50 | ++--------------+ +``` +## keyword +ASCII diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/bit_length.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/bit_length.md new file mode 100644 index 0000000000..be76317f38 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/bit_length.md @@ -0,0 +1,54 @@ +--- +{ + "title": "bit_length", + "language": "zh-CN" +} +--- + + + +# bit_length +## description +### Syntax + +`INT bit_length(VARCHAR str)` + + +返回字符串的位长度。 + +## example + +``` +mysql> select bit_length("abc"); ++-------------------+ +| bit_length('abc') | ++-------------------+ +| 24 | ++-------------------+ + +mysql> select bit_length("中国"); ++----------------------+ +| bit_length('中国') | ++----------------------+ +| 48 | ++----------------------+ +``` +## keyword +BIT_LENGTH diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/char_length.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/char_length.md new file mode 100644 index 0000000000..b74498b27d --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/char_length.md @@ -0,0 +1,54 @@ +--- +{ + "title": "CHAR_LENGTH", + "language": "zh-CN" +} +--- + + + +# char_length +## description +### Syntax + +`INT char_length(VARCHAR str)` + + +返回字符串的长度,对于多字节字符,返回字符数, 目前仅支持utf8 编码。这个函数还有一个别名 `character_length`。 + +## example + +``` +mysql> select char_length("abc"); ++--------------------+ +| char_length('abc') | ++--------------------+ +| 3 | ++--------------------+ + +mysql> select char_length("中国"); ++------------------- ---+ +| char_length('中国') | ++-----------------------+ +| 2 | ++-----------------------+ +``` +## keyword +CHAR_LENGTH, CHARACTER_LENGTH diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/concat.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/concat.md new file mode 100644 index 0000000000..460a5309c3 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/concat.md @@ -0,0 +1,61 @@ +--- +{ + "title": "concat", + "language": "zh-CN" +} +--- + + + +# concat +## description +### Syntax + +`VARCHAR concat(VARCHAR,...)` + + +将多个字符串连接起来, 如果参数中任意一个值是 NULL,那么返回的结果就是 NULL + +## example + +``` +mysql> select concat("a", "b"); ++------------------+ +| concat('a', 'b') | ++------------------+ +| ab | ++------------------+ + +mysql> select concat("a", "b", "c"); ++-----------------------+ +| concat('a', 'b', 'c') | ++-----------------------+ +| abc | ++-----------------------+ + +mysql> select concat("a", null, "c"); ++------------------------+ +| concat('a', NULL, 'c') | ++------------------------+ +| NULL | ++------------------------+ +``` +## keyword +CONCAT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/concat_ws.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/concat_ws.md new file mode 100644 index 0000000000..7710ec7cd9 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/concat_ws.md @@ -0,0 +1,63 @@ +--- +{ + "title": "concat_ws", + "language": "zh-CN" +} +--- + + + +# concat_ws +## description +### Syntax + +`VARCHAR concat_ws(VARCHAR sep, VARCHAR str,...)` + + +使用第一个参数 sep 作为连接符,将第二个参数以及后续所有参数拼接成一个字符串. +如果分隔符是 NULL,返回 NULL。 +`concat_ws`函数不会跳过空字符串,会跳过 NULL 值 + +## example + +``` +mysql> select concat_ws("or", "d", "is"); ++----------------------------+ +| concat_ws('or', 'd', 'is') | ++----------------------------+ +| doris | ++----------------------------+ + +mysql> select concat_ws(NULL, "d", "is"); ++----------------------------+ +| concat_ws(NULL, 'd', 'is') | ++----------------------------+ +| NULL | ++----------------------------+ + +mysql> select concat_ws("or", "d", NULL,"is"); ++---------------------------------+ +| concat_ws("or", "d", NULL,"is") | ++---------------------------------+ +| doris | ++---------------------------------+ +``` +## keyword +CONCAT_WS,CONCAT,WS diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/ends_with.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/ends_with.md new file mode 100644 index 0000000000..d839e0e162 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/ends_with.md @@ -0,0 +1,53 @@ +--- +{ + "title": "ends_with", + "language": "zh-CN" +} +--- + + + +# ends_with +## description +### Syntax + +`BOOLEAN ENDS_WITH (VARCHAR str, VARCHAR suffix)` + +如果字符串以指定后缀结尾,返回true。否则,返回false。任意参数为NULL,返回NULL。 + +## example + +``` +mysql> select ends_with("Hello doris", "doris"); ++-----------------------------------+ +| ends_with('Hello doris', 'doris') | ++-----------------------------------+ +| 1 | ++-----------------------------------+ + +mysql> select ends_with("Hello doris", "Hello"); ++-----------------------------------+ +| ends_with('Hello doris', 'Hello') | ++-----------------------------------+ +| 0 | ++-----------------------------------+ +``` +## keyword +ENDS_WITH diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/find_in_set.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/find_in_set.md new file mode 100644 index 0000000000..1b23156548 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/find_in_set.md @@ -0,0 +1,47 @@ +--- +{ + "title": "find_in_set", + "language": "zh-CN" +} +--- + + + +# find_in_set +## description +### Syntax + +`INT find_in_set(VARCHAR str, VARCHAR strlist)` + + +返回 strlist 中第一次出现 str 的位置(从1开始计数)。strlist 是用逗号分隔的字符串。如果没有找到,返回0。任意参数为 NULL ,返回 NULL。 + +## example + +``` +mysql> select find_in_set("b", "a,b,c"); ++---------------------------+ +| find_in_set('b', 'a,b,c') | ++---------------------------+ +| 2 | ++---------------------------+ +``` +## keyword +FIND_IN_SET,FIND,IN,SET diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/hex.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/hex.md new file mode 100644 index 0000000000..51d861f986 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/hex.md @@ -0,0 +1,85 @@ +--- +{ + "title": "hex", + "language": "zh-CN" +} +--- + + + +# hex +## description +### Syntax + +`VARCHAR hex(VARCHAR str)` + +`VARCHAR hex(BIGINT num)` + +如果输入参数是数字,返回十六进制值的字符串表示形式; + +如果输入参数是字符串,则将每个字符转化为两个十六进制的字符,将转化后的所有字符拼接为字符串输出 + + +## example + +``` +输入字符串 + +mysql> select hex('1'); ++----------+ +| hex('1') | ++----------+ +| 31 | ++----------+ + +mysql> select hex('@'); ++----------+ +| hex('@') | ++----------+ +| 40 | ++----------+ + +mysql> select hex('12'); ++-----------+ +| hex('12') | ++-----------+ +| 3132 | ++-----------+ +``` + +``` +输入数字 + +mysql> select hex(12); ++---------+ +| hex(12) | ++---------+ +| C | ++---------+ + +mysql> select hex(-1); ++------------------+ +| hex(-1) | ++------------------+ +| FFFFFFFFFFFFFFFF | ++------------------+ +``` +## keyword +HEX diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/instr.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/instr.md new file mode 100644 index 0000000000..c720b27b1b --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/instr.md @@ -0,0 +1,54 @@ +--- +{ + "title": "instr", + "language": "zh-CN" +} +--- + + + +# instr +## description +### Syntax + +`INT instr(VARCHAR str, VARCHAR substr)` + + +返回 substr 在 str 中第一次出现的位置(从1开始计数)。如果 substr 不在 str 中出现,则返回0。 + +## example + +``` +mysql> select instr("abc", "b"); ++-------------------+ +| instr('abc', 'b') | ++-------------------+ +| 2 | ++-------------------+ + +mysql> select instr("abc", "d"); ++-------------------+ +| instr('abc', 'd') | ++-------------------+ +| 0 | ++-------------------+ +``` +## keyword +INSTR diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/lcase.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/lcase.md new file mode 100644 index 0000000000..d801c5c054 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/lcase.md @@ -0,0 +1,37 @@ +--- +{ + "title": "lcase", + "language": "zh-CN" +} +--- + + + +# lcase +## description +### Syntax + +`INT lcase(VARCHAR str)` + + +与`lower`一致 + +## keyword +LCASE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/left.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/left.md new file mode 100644 index 0000000000..3471f2778d --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/left.md @@ -0,0 +1,47 @@ +--- +{ + "title": "left", + "language": "zh-CN" +} +--- + + + +# left +## description +### Syntax + +`VARCHAR left(VARCHAR str)` + + +它返回具有指定长度的字符串的左边部分, 长度的单位为utf8字符 + +## example + +``` +mysql> select left("Hello doris",5); ++------------------------+ +| left('Hello doris', 5) | ++------------------------+ +| Hello | ++------------------------+ +``` +## keyword +LEFT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/length.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/length.md new file mode 100644 index 0000000000..d0a5e27987 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/length.md @@ -0,0 +1,54 @@ +--- +{ + "title": "length", + "language": "zh-CN" +} +--- + + + +# length +## description +### Syntax + +`INT length(VARCHAR str)` + + +返回字符串的字节。 + +## example + +``` +mysql> select length("abc"); ++---------------+ +| length('abc') | ++---------------+ +| 3 | ++---------------+ + +mysql> select length("中国"); ++------------------+ +| length('中国') | ++------------------+ +| 6 | ++------------------+ +``` +## keyword +LENGTH diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/like/like.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/like/like.md new file mode 100644 index 0000000000..710cdf4df2 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/like/like.md @@ -0,0 +1,83 @@ +--- +{ + "title": "like", + "language": "zh-CN" +} +--- + + + +# like +## description +### syntax + +`BOOLEAN like(VARCHAR str, VARCHAR pattern)` + +对字符串 str 进行模糊匹配,匹配上的则返回 true,没匹配上则返回 false。 + +like 匹配/模糊匹配,会与 % 和 _ 结合使用。 + +百分号 '%' 代表零个、一个或多个字符。 + +下划线 '_' 代表单个字符。 + +``` +'a' // 精准匹配,和 `=` 效果一致 +'%a' // 以a结尾的数据 +'a%' // 以a开头的数据 +'%a%' // 含有a的数据 +'_a_' // 三位且中间字符是 a的数据 +'_a' // 两位且结尾字符是 a的数据 +'a_' // 两位且开头字符是 a的数据 +'a__b' // 四位且以字符a开头、b结尾的数据 +``` +## example + +``` +// table test ++-------+ +| k1 | ++-------+ +| b | +| bb | +| bab | +| a | ++-------+ + +// 返回 k1 字符串中包含 a 的数据 +mysql > select k1 from test where k1 like '%a%'; ++-------+ +| k1 | ++-------+ +| a | +| bab | ++-------+ + +// 返回 k1 字符串中等于 a 的数据 +mysql > select k1 from test where k1 like 'a'; ++-------+ +| k1 | ++-------+ +| a | ++-------+ +``` + +## keyword +LIKE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/like/not_like.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/like/not_like.md new file mode 100644 index 0000000000..776acab475 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/like/not_like.md @@ -0,0 +1,85 @@ +--- +{ + "title": "not like", + "language": "zh-CN" +} +--- + + + +# not like +## description +### syntax + +`BOOLEAN not like(VARCHAR str, VARCHAR pattern)` + +对字符串 str 进行模糊匹配,匹配上的则返回 false,没匹配上则返回 true。 + +like 匹配/模糊匹配,会与 % 和 _ 结合使用。 + +百分号 '%' 代表零个、一个或多个字符。 + +下划线 '_' 代表单个字符。 + +``` +'a' // 精准匹配,和 `=` 效果一致 +'%a' // 以a结尾的数据 +'a%' // 以a开头的数据 +'%a%' // 含有a的数据 +'_a_' // 三位且中间字母是 a 的数据 +'_a' // 两位且结尾字母是 a 的数据 +'a_' // 两位且开头字母是 a 的数据 +'a__b' // 四位且以字符a开头、b结尾的数据 +``` +## example + +``` +// table test ++-------+ +| k1 | ++-------+ +| b | +| bb | +| bab | +| a | ++-------+ + +// 返回 k1 字符串中不包含 a 的数据 +mysql > select k1 from test where k1 not like '%a%'; ++-------+ +| k1 | ++-------+ +| b | +| bb | ++-------+ + +// 返回 k1 字符串中不等于 a 的数据 +mysql > select k1 from test where k1 not like 'a'; ++-------+ +| k1 | ++-------+ +| b | +| bb | +| bab | ++-------+ +``` + +## keyword +LIKE, NOT, NOT LIKE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/locate.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/locate.md new file mode 100644 index 0000000000..c3d064835d --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/locate.md @@ -0,0 +1,61 @@ +--- +{ + "title": "locate", + "language": "zh-CN" +} +--- + + + +# locate +## description +### Syntax + +`INT locate(VARCHAR substr, VARCHAR str[, INT pos])` + + +返回 substr 在 str 中出现的位置(从1开始计数)。如果指定第3个参数 pos,则从 str 以 pos 下标开始的字符串处开始查找 substr 出现的位置。如果没有找到,返回0 + +## example + +``` +mysql> SELECT LOCATE('bar', 'foobarbar'); ++----------------------------+ +| locate('bar', 'foobarbar') | ++----------------------------+ +| 4 | ++----------------------------+ + +mysql> SELECT LOCATE('xbar', 'foobar'); ++--------------------------+ +| locate('xbar', 'foobar') | ++--------------------------+ +| 0 | ++--------------------------+ + +mysql> SELECT LOCATE('bar', 'foobarbar', 5); ++-------------------------------+ +| locate('bar', 'foobarbar', 5) | ++-------------------------------+ +| 7 | ++-------------------------------+ +``` +## keyword +LOCATE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/lower.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/lower.md new file mode 100644 index 0000000000..8bede875f8 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/lower.md @@ -0,0 +1,47 @@ +--- +{ + "title": "lower", + "language": "zh-CN" +} +--- + + + +# lower +## description +### Syntax + +`INT lower(VARCHAR str)` + + +将参数中所有的字符串都转换成小写 + +## example + +``` +mysql> SELECT lower("AbC123"); ++-----------------+ +| lower('AbC123') | ++-----------------+ +| abc123 | ++-----------------+ +``` +## keyword +LOWER diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/lpad.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/lpad.md new file mode 100644 index 0000000000..f5363350f5 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/lpad.md @@ -0,0 +1,54 @@ +--- +{ + "title": "lpad", + "language": "zh-CN" +} +--- + + + +# lpad +## description +### Syntax + +`VARCHAR lpad(VARCHAR str, INT len, VARCHAR pad)` + + +返回 str 中长度为 len(从首字母开始算起)的字符串。如果 len 大于 str 的长度,则在 str 的前面不断补充 pad 字符,直到该字符串的长度达到 len 为止。如果 len 小于 str 的长度,该函数相当于截断 str 字符串,只返回长度为 len 的字符串。len 指的是字符长度而不是字节长度。 + +## example + +``` +mysql> SELECT lpad("hi", 5, "xy"); ++---------------------+ +| lpad('hi', 5, 'xy') | ++---------------------+ +| xyxhi | ++---------------------+ + +mysql> SELECT lpad("hi", 1, "xy"); ++---------------------+ +| lpad('hi', 1, 'xy') | ++---------------------+ +| h | ++---------------------+ +``` +## keyword +LPAD diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/ltrim.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/ltrim.md new file mode 100644 index 0000000000..f8f37410b2 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/ltrim.md @@ -0,0 +1,47 @@ +--- +{ + "title": "ltrim", + "language": "zh-CN" +} +--- + + + +# ltrim +## description +### Syntax + +`VARCHAR ltrim(VARCHAR str)` + + +将参数 str 中从开始部分连续出现的空格去掉 + +## example + +``` +mysql> SELECT ltrim(' ab d'); ++------------------+ +| ltrim(' ab d') | ++------------------+ +| ab d | ++------------------+ +``` +## keyword +LTRIM diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/money_format.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/money_format.md new file mode 100644 index 0000000000..cf5ab699de --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/money_format.md @@ -0,0 +1,61 @@ +--- +{ + "title": "money_format", + "language": "zh-CN" +} +--- + + + +# money_format +## description +### Syntax + +`VARCHAR money_format(Number)` + + +将数字按照货币格式输出,整数部分每隔3位用逗号分隔,小数部分保留2位 + +## example + +``` +mysql> select money_format(17014116); ++------------------------+ +| money_format(17014116) | ++------------------------+ +| 17,014,116.00 | ++------------------------+ + +mysql> select money_format(1123.456); ++------------------------+ +| money_format(1123.456) | ++------------------------+ +| 1,123.46 | ++------------------------+ + +mysql> select money_format(1123.4); ++----------------------+ +| money_format(1123.4) | ++----------------------+ +| 1,123.40 | ++----------------------+ +``` +## keyword +MONEY_FORMAT,MONEY,FORMAT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/null_or_empty.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/null_or_empty.md new file mode 100644 index 0000000000..6283d917cb --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/null_or_empty.md @@ -0,0 +1,60 @@ +--- +{ + "title": "null_or_empty", + "language": "zh-CN" +} +--- + + + +# null_or_empty +## description +### Syntax + +`BOOLEAN NULL_OR_EMPTY (VARCHAR str)` + +如果字符串为空字符串或者NULL,返回true。否则,返回false。 + +## example + +``` +MySQL [(none)]> select null_or_empty(null); ++---------------------+ +| null_or_empty(NULL) | ++---------------------+ +| 1 | ++---------------------+ + +MySQL [(none)]> select null_or_empty(""); ++-------------------+ +| null_or_empty('') | ++-------------------+ +| 1 | ++-------------------+ + +MySQL [(none)]> select null_or_empty("a"); ++--------------------+ +| null_or_empty('a') | ++--------------------+ +| 0 | ++--------------------+ +``` +## keyword +NULL_OR_EMPTY \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/not_regexp.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/not_regexp.md new file mode 100644 index 0000000000..270a7e559b --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/not_regexp.md @@ -0,0 +1,56 @@ +--- +{ + "title": "not regexp", + "language": "zh-CN" +} +--- + + + +# not regexp +## description +### syntax + +`BOOLEAN not regexp(VARCHAR str, VARCHAR pattern)` + +对字符串 str 进行正则匹配,匹配上的则返回 false,没匹配上则返回 true。pattern 为正则表达式。 + +## example + +``` +// 查找 k1 字段中不以 'billie' 为开头的所有数据 +mysql > select k1 from test where k1 not regexp '^billie'; ++--------------------+ +| k1 | ++--------------------+ +| Emmy eillish | ++--------------------+ + +// 查找 k1 字段中不以 'ok' 为结尾的所有数据: +mysql > select k1 from test where k1 not regexp 'ok$'; ++------------+ +| k1 | ++------------+ +| It's true | ++------------+ +``` + +## keyword +REGEXP, NOT, NOT REGEXP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/regexp.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/regexp.md new file mode 100644 index 0000000000..fec12960a8 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/regexp.md @@ -0,0 +1,56 @@ +--- +{ + "title": "regexp", + "language": "zh-CN" +} +--- + + + +# regexp +## description +### syntax + +`BOOLEAN regexp(VARCHAR str, VARCHAR pattern)` + +对字符串 str 进行正则匹配,匹配上的则返回 true,没匹配上则返回 false。pattern 为正则表达式。 + +## example + +``` +// 查找 k1 字段中以 'billie' 为开头的所有数据 +mysql > select k1 from test where k1 regexp '^billie'; ++--------------------+ +| k1 | ++--------------------+ +| billie eillish | ++--------------------+ + +// 查找 k1 字段中以 'ok' 为结尾的所有数据: +mysql > select k1 from test where k1 regexp 'ok$'; ++----------+ +| k1 | ++----------+ +| It's ok | ++----------+ +``` + +## keyword +REGEXP diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/regexp_extract.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/regexp_extract.md new file mode 100644 index 0000000000..737721a5a4 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/regexp_extract.md @@ -0,0 +1,51 @@ +--- +{ + "title": "regexp_extract", + "language": "zh-CN" +} +--- + + + +# regexp_extract +## description +### Syntax + +`VARCHAR regexp_extract(VARCHAR str, VARCHAR pattern, int pos)` + + +对字符串 str 进行正则匹配,抽取符合 pattern 的第 pos 个匹配部分。需要 pattern 完全匹配 str 中的某部分,这样才能返回 pattern 部分中需匹配部分。如果没有匹配,返回空字符串。 + +## example + +``` +mysql> SELECT regexp_extract('AbCdE', '([[:lower:]]+)C([[:lower:]]+)', 1); ++-------------------------------------------------------------+ +| regexp_extract('AbCdE', '([[:lower:]]+)C([[:lower:]]+)', 1) | ++-------------------------------------------------------------+ +| b | ++-------------------------------------------------------------+ +mysql> SELECT regexp_extract('AbCdE', '([[:lower:]]+)C([[:lower:]]+)', 2); ++-------------------------------------------------------------+ +| regexp_extract('AbCdE', '([[:lower:]]+)C([[:lower:]]+)', 2) | ++-------------------------------------------------------------+ +| d | ++-------------------------------------------------------------+ +``` +## keyword +REGEXP_EXTRACT,REGEXP,EXTRACT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/regexp_replace.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/regexp_replace.md new file mode 100644 index 0000000000..9540f09f1c --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/regexp/regexp_replace.md @@ -0,0 +1,54 @@ +--- +{ + "title": "regexp_replace", + "language": "zh-CN" +} +--- + + + +# regexp_replace +## description +### Syntax + +`VARCHAR regexp_replace(VARCHAR str, VARCHAR pattern, VARCHAR repl)` + + +对字符串 str 进行正则匹配, 将命中 pattern 的部分使用 repl 来进行替换 + +## example + +``` +mysql> SELECT regexp_replace('a b c', " ", "-"); ++-----------------------------------+ +| regexp_replace('a b c', ' ', '-') | ++-----------------------------------+ +| a-b-c | ++-----------------------------------+ + +mysql> SELECT regexp_replace('a b c','(b)','<\\1>'); ++----------------------------------------+ +| regexp_replace('a b c', '(b)', '<\1>') | ++----------------------------------------+ +| a c | ++----------------------------------------+ +``` +## keyword +REGEXP_REPLACE,REGEXP,REPLACE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/repeat.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/repeat.md new file mode 100644 index 0000000000..58ca8a8690 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/repeat.md @@ -0,0 +1,54 @@ +--- +{ + "title": "repeat", + "language": "zh-CN" +} +--- + + + +# repeat +## description +### Syntax + +`VARCHAR repeat(VARCHAR str, INT count)` + + +将字符串 str 重复 count 次输出,count 小于1时返回空串,str,count 任一为NULL时,返回 NULL + +## example + +``` +mysql> SELECT repeat("a", 3); ++----------------+ +| repeat('a', 3) | ++----------------+ +| aaa | ++----------------+ + +mysql> SELECT repeat("a", -1); ++-----------------+ +| repeat('a', -1) | ++-----------------+ +| | ++-----------------+ +``` +## keyword +REPEAT, diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/replace.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/replace.md new file mode 100644 index 0000000000..dda2625df0 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/replace.md @@ -0,0 +1,46 @@ +--- +{ + "title": "replace", + "language": "zh-CN" +} +--- + + + +# replace +## description +### Syntax + +`VARCHAR REPLACE (VARCHAR str, VARCHAR old, VARCHAR new)` + +将str字符串中的old子串全部替换为new串 + +## example + +``` +mysql> select replace("http://www.baidu.com:9090", "9090", ""); ++------------------------------------------------------+ +| replace('http://www.baidu.com:9090', '9090', '') | ++------------------------------------------------------+ +| http://www.baidu.com: | ++------------------------------------------------------+ +``` +## keyword +REPLACE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/reverse.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/reverse.md new file mode 100644 index 0000000000..1daf7802e3 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/reverse.md @@ -0,0 +1,56 @@ +--- +{ + "title": "REVERSE", + "language": "zh-CN" +} +--- + + + +# reverse +## description +### Syntax + +`VARCHAR reverse(VARCHAR str)` + + +将字符串反转,返回的字符串的顺序和源字符串的顺序相反。 + +## example + +``` +mysql> SELECT REVERSE('hello'); ++------------------+ +| REVERSE('hello') | ++------------------+ +| olleh | ++------------------+ +1 row in set (0.00 sec) + +mysql> SELECT REVERSE('你好'); ++------------------+ +| REVERSE('你好') | ++------------------+ +| 好你 | ++------------------+ +1 row in set (0.00 sec) +``` +## keyword +REVERSE diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/right.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/right.md new file mode 100644 index 0000000000..5a28f59af6 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/right.md @@ -0,0 +1,47 @@ +--- +{ + "title": "right", + "language": "zh-CN" +} +--- + + + +# right +## description +### Syntax + +`VARCHAR right(VARCHAR str)` + + +它返回具有指定长度的字符串的右边部分, 长度的单位为utf8字符 + +## example + +``` +mysql> select right("Hello doris",5); ++-------------------------+ +| right('Hello doris', 5) | ++-------------------------+ +| doris | ++-------------------------+ +``` +## keyword +RIGHT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/rpad.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/rpad.md new file mode 100644 index 0000000000..b44b0d7862 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/rpad.md @@ -0,0 +1,54 @@ +--- +{ + "title": "rpad", + "language": "zh-CN" +} +--- + + + +# rpad +## description +### Syntax + +`VARCHAR rpad(VARCHAR str, INT len, VARCHAR pad)` + + +返回 str 中长度为 len(从首字母开始算起)的字符串。如果 len 大于 str 的长度,则在 str 的后面不断补充 pad 字符,直到该字符串的长度达到 len 为止。如果 len 小于 str 的长度,该函数相当于截断 str 字符串,只返回长度为 len 的字符串。len 指的是字符长度而不是字节长度。 + +## example + +``` +mysql> SELECT rpad("hi", 5, "xy"); ++---------------------+ +| rpad('hi', 5, 'xy') | ++---------------------+ +| hixyx | ++---------------------+ + +mysql> SELECT rpad("hi", 1, "xy"); ++---------------------+ +| rpad('hi', 1, 'xy') | ++---------------------+ +| h | ++---------------------+ +``` +## keyword +RPAD diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/split_part.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/split_part.md new file mode 100644 index 0000000000..67c0d6504a --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/split_part.md @@ -0,0 +1,69 @@ +--- +{ + "title": "split_part", + "language": "zh-CN" +} +--- + + + +# split_part +## description +### Syntax + +`VARCHAR split_part(VARCHAR content, VARCHAR delimiter, INT field)` + + +根据分割符拆分字符串, 返回指定的分割部分(从一开始计数)。 + +## example + +``` +mysql> select split_part("hello world", " ", 1); ++----------------------------------+ +| split_part('hello world', ' ', 1) | ++----------------------------------+ +| hello | ++----------------------------------+ + + +mysql> select split_part("hello world", " ", 2); ++----------------------------------+ +| split_part('hello world', ' ', 2) | ++----------------------------------+ +| world | ++----------------------------------+ + +mysql> select split_part("2019年7月8号", "月", 1); ++-----------------------------------------+ +| split_part('2019年7月8号', '月', 1) | ++-----------------------------------------+ +| 2019年7 | ++-----------------------------------------+ + +mysql> select split_part("abca", "a", 1); ++----------------------------+ +| split_part('abca', 'a', 1) | ++----------------------------+ +| | ++----------------------------+ +``` +## keyword +SPLIT_PART,SPLIT,PART diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/starts_with.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/starts_with.md new file mode 100644 index 0000000000..98c5582cec --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/starts_with.md @@ -0,0 +1,53 @@ +--- +{ + "title": "starts_with", + "language": "zh-CN" +} +--- + + + +# starts_with +## description +### Syntax + +`BOOLEAN STARTS_WITH (VARCHAR str, VARCHAR prefix)` + +如果字符串以指定前缀开头,返回true。否则,返回false。任意参数为NULL,返回NULL。 + +## example + +``` +MySQL [(none)]> select starts_with("hello world","hello"); ++-------------------------------------+ +| starts_with('hello world', 'hello') | ++-------------------------------------+ +| 1 | ++-------------------------------------+ + +MySQL [(none)]> select starts_with("hello world","world"); ++-------------------------------------+ +| starts_with('hello world', 'world') | ++-------------------------------------+ +| 0 | ++-------------------------------------+ +``` +## keyword +STARTS_WITH \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/strleft.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/strleft.md new file mode 100644 index 0000000000..5be123c23d --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/strleft.md @@ -0,0 +1,47 @@ +--- +{ + "title": "strleft", + "language": "zh-CN" +} +--- + + + +# strleft +## description +### Syntax + +`VARCHAR strleft(VARCHAR str)` + + +它返回具有指定长度的字符串的左边部分,长度的单位为utf8字符 + +## example + +``` +mysql> select strleft("Hello doris",5); ++------------------------+ +| strleft('Hello doris', 5) | ++------------------------+ +| Hello | ++------------------------+ +``` +## keyword +STRLEFT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/strright.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/strright.md new file mode 100644 index 0000000000..67d2fd4348 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/strright.md @@ -0,0 +1,47 @@ +--- +{ + "title": "strright", + "language": "zh-CN" +} +--- + + + +# strright +## description +### Syntax + +`VARCHAR strright(VARCHAR str)` + + +它返回具有指定长度的字符串的右边部分, 长度的单位为utf8字符 + +## example + +``` +mysql> select strright("Hello doris",5); ++-------------------------+ +| strright('Hello doris', 5) | ++-------------------------+ +| doris | ++-------------------------+ +``` +## keyword +STRRIGHT diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/substring.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/substring.md new file mode 100644 index 0000000000..c56bc989fa --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/substring.md @@ -0,0 +1,72 @@ +--- +{ + "title": "substring", + "language": "zh-CN" +} +--- + + + +# substring +## description +### Syntax + +`VARCHAR substring(VARCHAR str, INT pos[, INT len])` + +没有 `len` 参数时返回从位置 `pos` 开始的字符串 `str` 的一个子字符串, +在有 `len` 参数时返回从位置 `pos` 开始的字符串 `str` 的一个长度为 `len` 子字符串, +`pos` 参数可以使用负值,在这种情况下,子字符串是以字符串 `str` 末尾开始计算 `pos` 个字符,而不是开头, +`pos` 的值为 0 返回一个空字符串。 + +对于所有形式的 SUBSTRING(),要从中提取子字符串的字符串中第一个字符的位置为1。 + +## example + +``` +mysql> select substring('abc1', 2); ++-----------------------------+ +| substring('abc1', 2) | ++-----------------------------+ +| bc1 | ++-----------------------------+ + +mysql> select substring('abc1', -2); ++-----------------------------+ +| substring('abc1', -2) | ++-----------------------------+ +| c1 | ++-----------------------------+ + +mysql> select substring('abc1', 5); ++-----------------------------+ +| substring('abc1', 5) | ++-----------------------------+ +| NULL | ++-----------------------------+ + +mysql> select substring('abc1def', 2, 2); ++-----------------------------+ +| substring('abc1def', 2, 2) | ++-----------------------------+ +| bc | ++-----------------------------+ +``` +## keyword +SUBSTRING diff --git a/new-docs/zh-CN/sql-manual/sql-functions/string-functions/unhex.md b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/unhex.md new file mode 100644 index 0000000000..f33e75d73e --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/string-functions/unhex.md @@ -0,0 +1,63 @@ +--- +{ + "title": "unhex", + "language": "zh-CN" +} +--- + + + +# unhex +## description +### Syntax + +`VARCHAR unhex(VARCHAR str)` + +输入字符串,如果字符串长度为0或者为奇数,返回空串; +如果字符串中包含`[0-9]、[a-z]、[A-Z]`之外的字符,返回空串; +其他情况每两个字符为一组转化为16进制后的字符,然后拼接成字符串输出 + + +## example + +``` +mysql> select unhex('@'); ++------------+ +| unhex('@') | ++------------+ +| | ++------------+ + +mysql> select unhex('41'); ++-------------+ +| unhex('41') | ++-------------+ +| A | ++-------------+ + +mysql> select unhex('4142'); ++---------------+ +| unhex('4142') | ++---------------+ +| AB | ++---------------+ +``` +## keyword +UNHEX diff --git a/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-bitmap.md b/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-bitmap.md new file mode 100644 index 0000000000..99f79711ac --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-bitmap.md @@ -0,0 +1,157 @@ +--- +{ + "title": "explode_bitmap", + "language": "zh-CN" +} +--- + + + +# explode_bitmap + +## description + +表函数,需配合 Lateral View 使用。 + +展开一个bitmap类型。 + +语法: + +``` +explode_bitmap(bitmap) +``` + +## example + +原表数据: + +``` +mysql> select k1 from example1 order by k1; ++------+ +| k1 | ++------+ +| 1 | +| 2 | +| 3 | +| 4 | +| 5 | +| 6 | ++------+ +``` + +Lateral View: + +``` +mysql> select k1, e1 from example1 lateral view explode_bitmap(bitmap_empty()) tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 2 | NULL | +| 3 | NULL | +| 4 | NULL | +| 5 | NULL | +| 6 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_bitmap(bitmap_from_string("1")) tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | 1 | +| 2 | 1 | +| 3 | 1 | +| 4 | 1 | +| 5 | 1 | +| 6 | 1 | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_bitmap(bitmap_from_string("1,2")) tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | 1 | +| 1 | 2 | +| 2 | 1 | +| 2 | 2 | +| 3 | 1 | +| 3 | 2 | +| 4 | 1 | +| 4 | 2 | +| 5 | 1 | +| 5 | 2 | +| 6 | 1 | +| 6 | 2 | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_bitmap(bitmap_from_string("1,1000")) tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | 1 | +| 1 | 1000 | +| 2 | 1 | +| 2 | 1000 | +| 3 | 1 | +| 3 | 1000 | +| 4 | 1 | +| 4 | 1000 | +| 5 | 1 | +| 5 | 1000 | +| 6 | 1 | +| 6 | 1000 | ++------+------+ + +mysql> select k1, e1, e2 from example1 +lateral view explode_bitmap(bitmap_from_string("1,1000")) tmp1 as e1 +lateral view explode_split("a,b", ",") tmp2 as e2 order by k1, e1, e2; ++------+------+------+ +| k1 | e1 | e2 | ++------+------+------+ +| 1 | 1 | a | +| 1 | 1 | b | +| 1 | 1000 | a | +| 1 | 1000 | b | +| 2 | 1 | a | +| 2 | 1 | b | +| 2 | 1000 | a | +| 2 | 1000 | b | +| 3 | 1 | a | +| 3 | 1 | b | +| 3 | 1000 | a | +| 3 | 1000 | b | +| 4 | 1 | a | +| 4 | 1 | b | +| 4 | 1000 | a | +| 4 | 1000 | b | +| 5 | 1 | a | +| 5 | 1 | b | +| 5 | 1000 | a | +| 5 | 1000 | b | +| 6 | 1 | a | +| 6 | 1 | b | +| 6 | 1000 | a | +| 6 | 1000 | b | ++------+------+------+ +``` + +## keyword + + explode_bitmap \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-json-array.md b/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-json-array.md new file mode 100644 index 0000000000..8332d6a8e4 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-json-array.md @@ -0,0 +1,286 @@ +--- +{ + "title": "explode_json_array", + "language": "zh-CN" +} +--- + + + +# `explode_json_array` + +## description + +表函数,需配合 Lateral View 使用。 + +展开一个 json 数组。根据数组元素类型,有三种函数名称。分别对应整型、浮点和字符串数组。 + +语法: + +``` +explode_json_array_int(json_str) +explode_json_array_double(json_str) +explode_json_array_string(json_str) +``` + +## example + +原表数据: + +``` +mysql> select k1 from example1 order by k1; ++------+ +| k1 | ++------+ +| 1 | +| 2 | +| 3 | +| 4 | +| 5 | +| 6 | ++------+ +``` + +Lateral View: + +``` +mysql> select k1, e1 from example1 lateral view explode_json_array_int('[]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 2 | NULL | +| 3 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_int('[1,2,3]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | 1 | +| 1 | 2 | +| 1 | 3 | +| 2 | 1 | +| 2 | 2 | +| 2 | 3 | +| 3 | 1 | +| 3 | 2 | +| 3 | 3 | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_int('[1,"b",3]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 1 | 1 | +| 1 | 3 | +| 2 | NULL | +| 2 | 1 | +| 2 | 3 | +| 3 | NULL | +| 3 | 1 | +| 3 | 3 | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_int('["a","b","c"]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 1 | NULL | +| 1 | NULL | +| 2 | NULL | +| 2 | NULL | +| 2 | NULL | +| 3 | NULL | +| 3 | NULL | +| 3 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_int('{"a": 3}') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 2 | NULL | +| 3 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_double('[]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 2 | NULL | +| 3 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_double('[1,2,3]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 1 | NULL | +| 1 | NULL | +| 2 | NULL | +| 2 | NULL | +| 2 | NULL | +| 3 | NULL | +| 3 | NULL | +| 3 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_double('[1,"b",3]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 1 | NULL | +| 1 | NULL | +| 2 | NULL | +| 2 | NULL | +| 2 | NULL | +| 3 | NULL | +| 3 | NULL | +| 3 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_double('[1.0,2.0,3.0]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | 1 | +| 1 | 2 | +| 1 | 3 | +| 2 | 1 | +| 2 | 2 | +| 2 | 3 | +| 3 | 1 | +| 3 | 2 | +| 3 | 3 | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_double('[1,"b",3]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 1 | NULL | +| 1 | NULL | +| 2 | NULL | +| 2 | NULL | +| 2 | NULL | +| 3 | NULL | +| 3 | NULL | +| 3 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_double('["a","b","c"]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 1 | NULL | +| 1 | NULL | +| 2 | NULL | +| 2 | NULL | +| 2 | NULL | +| 3 | NULL | +| 3 | NULL | +| 3 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_double('{"a": 3}') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 2 | NULL | +| 3 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_string('[]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 2 | NULL | +| 3 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_string('[1.0,2.0,3.0]') tmp1 as e1 order by k1, e1; ++------+----------+ +| k1 | e1 | ++------+----------+ +| 1 | 1.000000 | +| 1 | 2.000000 | +| 1 | 3.000000 | +| 2 | 1.000000 | +| 2 | 2.000000 | +| 2 | 3.000000 | +| 3 | 1.000000 | +| 3 | 2.000000 | +| 3 | 3.000000 | ++------+----------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_string('[1,"b",3]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | 1 | +| 1 | 3 | +| 1 | b | +| 2 | 1 | +| 2 | 3 | +| 2 | b | +| 3 | 1 | +| 3 | 3 | +| 3 | b | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_string('["a","b","c"]') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | a | +| 1 | b | +| 1 | c | +| 2 | a | +| 2 | b | +| 2 | c | +| 3 | a | +| 3 | b | +| 3 | c | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_json_array_string('{"a": 3}') tmp1 as e1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | NULL | +| 2 | NULL | +| 3 | NULL | ++------+------+ +``` + +## keyword + + explode_json_array \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-numbers.md b/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-numbers.md new file mode 100644 index 0000000000..66e7f54dc2 --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-numbers.md @@ -0,0 +1,57 @@ +--- +{ + "title": "explode_numbers", + "language": "zh-CN" +} +--- + + + +# explode_numbers + +## description + +表函数,需配合 Lateral View 使用。 + +获得一个[0,n)的序列。 + +语法: + +``` +explode_numbers(n) +``` + +## example + +``` +mysql> select e1 from (select 1 k1) as t lateral view explode_numbers(5) tmp1 as e1; ++------+ +| e1 | ++------+ +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | ++------+ +``` +## keyword + + explode_numbers \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-split.md b/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-split.md new file mode 100644 index 0000000000..d7c403186e --- /dev/null +++ b/new-docs/zh-CN/sql-manual/sql-functions/table-functions/explode-split.md @@ -0,0 +1,112 @@ +--- +{ + "title": "explode_split", + "language": "zh-CN" +} +--- + + + +# explode_split + +## description + +表函数,需配合 Lateral View 使用。 + +将一个字符串按指定的分隔符分割成多个子串。 + +语法: + +``` +explode_split(str, delimiter) +``` + +## example + +原表数据: + +``` +mysql> select * from example1 order by k1; ++------+---------+ +| k1 | k2 | ++------+---------+ +| 1 | | +| 2 | NULL | +| 3 | , | +| 4 | 1 | +| 5 | 1,2,3 | +| 6 | a, b, c | ++------+---------+ +``` + +Lateral View: + +``` +mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 1 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 1 | | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 2 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 2 | NULL | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 3 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 3 | | +| 3 | | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 4 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 4 | 1 | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 5 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 5 | 1 | +| 5 | 2 | +| 5 | 3 | ++------+------+ + +mysql> select k1, e1 from example1 lateral view explode_split(k2, ',') tmp1 as e1 where k1 = 6 order by k1, e1; ++------+------+ +| k1 | e1 | ++------+------+ +| 6 | b | +| 6 | c | +| 6 | a | ++------+------+ +``` + +## keyword + + explode_split \ No newline at end of file diff --git a/new-docs/zh-CN/sql-manual/sql-functions/window-function.md b/new-docs/zh-CN/sql-manual/sql-functions/window-function.md index 9f0bc6fdb2..7cbde40c30 100644 --- a/new-docs/zh-CN/sql-manual/sql-functions/window-function.md +++ b/new-docs/zh-CN/sql-manual/sql-functions/window-function.md @@ -11,4 +11,477 @@ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -# Doris 窗口函数使用 \ No newline at end of file +# Doris 窗口函数使用 + +## 窗口函数介绍 + +分析函数是一类特殊的内置函数。和聚合函数类似,分析函数也是对于多个输入行做计算得到一个数据值。不同的是,分析函数是在一个特定的窗口内对输入数据做处理,而不是按照 group by 来分组计算。每个窗口内的数据可以用 over() 从句进行排序和分组。分析函数会对结果集的每一行计算出一个单独的值,而不是每个 group by 分组计算一个值。这种灵活的方式允许用户在 select 从句中增加额外的列,给用户提供了更多的机会来对结果集进行重新组织和过滤。分析函数只能出现在 select 列表和最外层的 order by 从句中。在查询过程中,分析函数会在最后生效,就是说,在执行完 join,where 和 group by 等操作之后再执行。分析函数在金融和科学计算领域经常被使用到,用来分析趋势、计算离群值以及对大量数据进行分桶分析等。 + +分析函数的语法: + +```sql +function(args) OVER(partition_by_clause order_by_clause [window_clause]) +partition_by_clause ::= PARTITION BY expr [, expr ...] +order_by_clause ::= ORDER BY expr [ASC | DESC] [, expr [ASC | DESC] ...] +``` + +### Function + +目前支持的 Function 包括 AVG(), COUNT(), DENSE_RANK(), FIRST_VALUE(), LAG(), LAST_VALUE(), LEAD(), MAX(), MIN(), RANK(), ROW_NUMBER() 和 SUM()。 + +### PARTITION BY从句 + +Partition By 从句和 Group By 类似。它把输入行按照指定的一列或多列分组,相同值的行会被分到一组。 + +### ORDER BY从句 + +Order By从句和外层的Order By基本一致。它定义了输入行的排列顺序,如果指定了 Partition By,则 Order By 定义了每个 Partition 分组内的顺序。与外层 Order By 的唯一不同点是,OVER 从句中的 Order By n(n是正整数)相当于不做任何操作,而外层的 Order By n表示按照第n列排序。 + +举例: + +这个例子展示了在select列表中增加一个id列,它的值是1,2,3等等,顺序按照events表中的date_and_time列排序。 + +```sql +SELECT +row_number() OVER (ORDER BY date_and_time) AS id, +c1, c2, c3, c4 +FROM events; +``` + +### Window从句 + +Window 从句用来为分析函数指定一个运算范围,以当前行为准,前后若干行作为分析函数运算的对象。Window 从句支持的方法有:AVG(), COUNT(), FIRST_VALUE(), LAST_VALUE() 和 SUM()。对于 MAX() 和 MIN(), window 从句可以指定开始范围 UNBOUNDED PRECEDING + +语法: + +```sql +ROWS BETWEEN [ { m | UNBOUNDED } PRECEDING | CURRENT ROW] [ AND [CURRENT ROW | { UNBOUNDED | n } FOLLOWING] ] +``` + +### 举例: + +假设我们有如下的股票数据,股票代码是 JDR,closing price 是每天的收盘价。 + +```sql +create table stock_ticker (stock_symbol string, closing_price decimal(8,2), closing_date timestamp); +...load some data... +select * from stock_ticker order by stock_symbol, closing_date + | stock_symbol | closing_price | closing_date | + |--------------|---------------|---------------------| + | JDR | 12.86 | 2014-10-02 00:00:00 | + | JDR | 12.89 | 2014-10-03 00:00:00 | + | JDR | 12.94 | 2014-10-04 00:00:00 | + | JDR | 12.55 | 2014-10-05 00:00:00 | + | JDR | 14.03 | 2014-10-06 00:00:00 | + | JDR | 14.75 | 2014-10-07 00:00:00 | + | JDR | 13.98 | 2014-10-08 00:00:00 | +``` + +这个查询使用分析函数产生 moving_average 这一列,它的值是3天的股票均价,即前一天、当前以及后一天三天的均价。第一天没有前一天的值,最后一天没有后一天的值,所以这两行只计算了两天的均值。这里 Partition By 没有起到作用,因为所有的数据都是 JDR 的数据,但如果还有其他股票信息,Partition By 会保证分析函数值作用在本 Partition 之内。 + +```sql +select stock_symbol, closing_date, closing_price, +avg(closing_price) over (partition by stock_symbol order by closing_date +rows between 1 preceding and 1 following) as moving_average +from stock_ticker; + | stock_symbol | closing_date | closing_price | moving_average | + |--------------|---------------------|---------------|----------------| + | JDR | 2014-10-02 00:00:00 | 12.86 | 12.87 | + | JDR | 2014-10-03 00:00:00 | 12.89 | 12.89 | + | JDR | 2014-10-04 00:00:00 | 12.94 | 12.79 | + | JDR | 2014-10-05 00:00:00 | 12.55 | 13.17 | + | JDR | 2014-10-06 00:00:00 | 14.03 | 13.77 | + | JDR | 2014-10-07 00:00:00 | 14.75 | 14.25 | + | JDR | 2014-10-08 00:00:00 | 13.98 | 14.36 | +``` + +## Function使用举例 + +本节介绍 Doris 中可以用作分析函数的方法。 + +### AVG() + +语法: + +```sql +AVG([DISTINCT | ALL] *expression*) [OVER (*analytic_clause*)] +``` + +举例: + +计算当前行和它前后各一行数据的x平均值 + +```sql +select x, property, +avg(x) over +( +partition by property +order by x +rows between 1 preceding and 1 following +) as 'moving average' +from int_t where property in ('odd','even'); + | x | property | moving average | + |----|----------|----------------| + | 2 | even | 3 | + | 4 | even | 4 | + | 6 | even | 6 | + | 8 | even | 8 | + | 10 | even | 9 | + | 1 | odd | 2 | + | 3 | odd | 3 | + | 5 | odd | 5 | + | 7 | odd | 7 | + | 9 | odd | 8 | +``` + +### COUNT() + +语法: + +```sql +COUNT([DISTINCT | ALL] expression) [OVER (analytic_clause)] +``` + +举例: + +计算从当前行到第一行x出现的次数。 + +```sql +select x, property, +count(x) over +( +partition by property +order by x +rows between unbounded preceding and current row +) as 'cumulative total' +from int_t where property in ('odd','even'); + | x | property | cumulative count | + |----|----------|------------------| + | 2 | even | 1 | + | 4 | even | 2 | + | 6 | even | 3 | + | 8 | even | 4 | + | 10 | even | 5 | + | 1 | odd | 1 | + | 3 | odd | 2 | + | 5 | odd | 3 | + | 7 | odd | 4 | + | 9 | odd | 5 | +``` + +### DENSE_RANK() + +DENSE_RANK() 函数用来表示排名,与RANK()不同的是,DENSE_RANK() 不会出现空缺数字。比如,如果出现了两个并列的1,DENSE_RANK() 的第三个数仍然是2,而RANK()的第三个数是3。 + +语法: + +```sql +DENSE_RANK() OVER(partition_by_clause order_by_clause) +``` + +举例: + +下例展示了按照 property 列分组对x列排名: + +```sql + select x, y, dense_rank() over(partition by x order by y) as rank from int_t; + | x | y | rank | + |----|------|----------| + | 1 | 1 | 1 | + | 1 | 2 | 2 | + | 1 | 2 | 2 | + | 2 | 1 | 1 | + | 2 | 2 | 2 | + | 2 | 3 | 3 | + | 3 | 1 | 1 | + | 3 | 1 | 1 | + | 3 | 2 | 2 | +``` + +### FIRST_VALUE() + +FIRST_VALUE() 返回窗口范围内的第一个值。 + +语法: + +```sql +FIRST_VALUE(expr) OVER(partition_by_clause order_by_clause [window_clause]) +``` + +举例: + +我们有如下数据 + +```sql + select name, country, greeting from mail_merge; + | name | country | greeting | + |---------|---------|--------------| + | Pete | USA | Hello | + | John | USA | Hi | + | Boris | Germany | Guten tag | + | Michael | Germany | Guten morgen | + | Bjorn | Sweden | Hej | + | Mats | Sweden | Tja | +``` + +使用 FIRST_VALUE(),根据 country 分组,返回每个分组中第一个 greeting 的值: + +```sql +select country, name, +first_value(greeting) +over (partition by country order by name, greeting) as greeting from mail_merge; +| country | name | greeting | +|---------|---------|-----------| +| Germany | Boris | Guten tag | +| Germany | Michael | Guten tag | +| Sweden | Bjorn | Hej | +| Sweden | Mats | Hej | +| USA | John | Hi | +| USA | Pete | Hi | +``` + +### LAG() + +LAG() 方法用来计算当前行向前数若干行的值。 + +语法: + +```sql +LAG (expr, offset, default) OVER (partition_by_clause order_by_clause) +``` + +举例: + +计算前一天的收盘价 + +```sql +select stock_symbol, closing_date, closing_price, +lag(closing_price,1, 0) over (partition by stock_symbol order by closing_date) as "yesterday closing" +from stock_ticker +order by closing_date; +| stock_symbol | closing_date | closing_price | yesterday closing | +|--------------|---------------------|---------------|-------------------| +| JDR | 2014-09-13 00:00:00 | 12.86 | 0 | +| JDR | 2014-09-14 00:00:00 | 12.89 | 12.86 | +| JDR | 2014-09-15 00:00:00 | 12.94 | 12.89 | +| JDR | 2014-09-16 00:00:00 | 12.55 | 12.94 | +| JDR | 2014-09-17 00:00:00 | 14.03 | 12.55 | +| JDR | 2014-09-18 00:00:00 | 14.75 | 14.03 | +| JDR | 2014-09-19 00:00:00 | 13.98 | 14.75 | +``` + +### LAST_VALUE() + +LAST_VALUE() 返回窗口范围内的最后一个值。与 FIRST_VALUE() 相反。 + +语法: + +```sql +LAST_VALUE(expr) OVER(partition_by_clause order_by_clause [window_clause]) +``` + +使用FIRST_VALUE()举例中的数据: + +```sql +select country, name, +last_value(greeting) +over (partition by country order by name, greeting) as greeting +from mail_merge; +| country | name | greeting | +|---------|---------|--------------| +| Germany | Boris | Guten morgen | +| Germany | Michael | Guten morgen | +| Sweden | Bjorn | Tja | +| Sweden | Mats | Tja | +| USA | John | Hello | +| USA | Pete | Hello | +``` + +### LEAD() + +LEAD() 方法用来计算当前行向后数若干行的值。 + +语法: + +```sql +LEAD (expr, offset, default]) OVER (partition_by_clause order_by_clause) +``` + +举例: + +计算第二天的收盘价对比当天收盘价的走势,即第二天收盘价比当天高还是低。 + +```sql +select stock_symbol, closing_date, closing_price, +case +(lead(closing_price,1, 0) +over (partition by stock_symbol order by closing_date)-closing_price) > 0 +when true then "higher" +when false then "flat or lower" +end as "trending" +from stock_ticker +order by closing_date; +| stock_symbol | closing_date | closing_price | trending | +|--------------|---------------------|---------------|---------------| +| JDR | 2014-09-13 00:00:00 | 12.86 | higher | +| JDR | 2014-09-14 00:00:00 | 12.89 | higher | +| JDR | 2014-09-15 00:00:00 | 12.94 | flat or lower | +| JDR | 2014-09-16 00:00:00 | 12.55 | higher | +| JDR | 2014-09-17 00:00:00 | 14.03 | higher | +| JDR | 2014-09-18 00:00:00 | 14.75 | flat or lower | +| JDR | 2014-09-19 00:00:00 | 13.98 | flat or lower | +``` + +### MAX() + +语法: + +```sql +MAX([DISTINCT | ALL] expression) [OVER (analytic_clause)] +``` + +举例: + +计算从第一行到当前行之后一行的最大值 + +```sql +select x, property, +max(x) over +( +order by property, x +rows between unbounded preceding and 1 following +) as 'local maximum' +from int_t where property in ('prime','square'); +| x | property | local maximum | +|---|----------|---------------| +| 2 | prime | 3 | +| 3 | prime | 5 | +| 5 | prime | 7 | +| 7 | prime | 7 | +| 1 | square | 7 | +| 4 | square | 9 | +| 9 | square | 9 | +``` + +### MIN() + +语法: + +```sql +MIN([DISTINCT | ALL] expression) [OVER (analytic_clause)] +``` + +举例: + +计算从第一行到当前行之后一行的最小值 + +```sql +select x, property, +min(x) over +( +order by property, x desc +rows between unbounded preceding and 1 following +) as 'local minimum' +from int_t where property in ('prime','square'); +| x | property | local minimum | +|---|----------|---------------| +| 7 | prime | 5 | +| 5 | prime | 3 | +| 3 | prime | 2 | +| 2 | prime | 2 | +| 9 | square | 2 | +| 4 | square | 1 | +| 1 | square | 1 | +``` + +### RANK() + +RANK() 函数用来表示排名,与 DENSE_RANK() 不同的是,RANK() 会出现空缺数字。比如,如果出现了两个并列的1, RANK() 的第三个数就是3,而不是2。 + +语法: + +```sql +RANK() OVER(partition_by_clause order_by_clause) +``` + +举例: + +根据 x 进行排名 + +```sql +select x, y, rank() over(partition by x order by y) as rank from int_t; +| x | y | rank | +|----|------|----------| +| 1 | 1 | 1 | +| 1 | 2 | 2 | +| 1 | 2 | 2 | +| 2 | 1 | 1 | +| 2 | 2 | 2 | +| 2 | 3 | 3 | +| 3 | 1 | 1 | +| 3 | 1 | 1 | +| 3 | 2 | 3 | +``` + +### ROW_NUMBER() + +为每个 Partition 的每一行返回一个从1开始连续递增的整数。与 RANK() 和 DENSE_RANK() 不同的是,ROW_NUMBER() 返回的值不会重复也不会出现空缺,是连续递增的。 + +语法: + +```sql +ROW_NUMBER() OVER(partition_by_clause order_by_clause) +``` + +举例: + +```sql +select x, y, row_number() over(partition by x order by y) as rank from int_t; +| x | y | rank | +|---|------|----------| +| 1 | 1 | 1 | +| 1 | 2 | 2 | +| 1 | 2 | 3 | +| 2 | 1 | 1 | +| 2 | 2 | 2 | +| 2 | 3 | 3 | +| 3 | 1 | 1 | +| 3 | 1 | 2 | +| 3 | 2 | 3 | +``` + +### SUM() + +语法: + +```sql +SUM([DISTINCT | ALL] expression) [OVER (analytic_clause)] +``` + +举例: + +按照 property 进行分组,在组内计算当前行以及前后各一行的x列的和。 + +```sql +select x, property, +sum(x) over +( +partition by property +order by x +rows between 1 preceding and 1 following +) as 'moving total' +from int_t where property in ('odd','even'); +| x | property | moving total | +|----|----------|--------------| +| 2 | even | 6 | +| 4 | even | 12 | +| 6 | even | 18 | +| 8 | even | 24 | +| 10 | even | 18 | +| 1 | odd | 4 | +| 3 | odd | 9 | +| 5 | odd | 15 | +| 7 | odd | 21 | +| 9 | odd | 16 | +``` +