Add SQL function Chinese documentation (#8995)
[Refactor][Doc] Add SQL function Chinese documentation
This commit is contained in:
@ -491,7 +491,6 @@ module.exports = [
|
||||
initialOpenGroupIndex: -1,
|
||||
children: [
|
||||
"CREATE-USER",
|
||||
"ALTER-USER",
|
||||
"CREATE-ROLE",
|
||||
"DROP-ROLE",
|
||||
"DROP-USER",
|
||||
|
||||
@ -491,7 +491,6 @@ module.exports = [
|
||||
initialOpenGroupIndex: -1,
|
||||
children: [
|
||||
"CREATE-USER",
|
||||
"ALTER-USER",
|
||||
"CREATE-ROLE",
|
||||
"DROP-ROLE",
|
||||
"DROP-USER",
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
---
|
||||
{
|
||||
"title": "BE 监控项",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# BE 监控项
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
---
|
||||
{
|
||||
"title": "FE 监控项",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# FE 监控项
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
---
|
||||
{
|
||||
"title": "APPROX_COUNT_DISTINCT",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,57 @@
|
||||
---
|
||||
{
|
||||
"title": "AVG",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,146 @@
|
||||
---
|
||||
{
|
||||
"title": "BITMAP_UNION",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
61
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/count.md
Executable file
61
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/count.md
Executable file
@ -0,0 +1,61 @@
|
||||
---
|
||||
{
|
||||
"title": "COUNT",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,70 @@
|
||||
---
|
||||
{
|
||||
"title": "GROUP_CONCAT",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,52 @@
|
||||
---
|
||||
{
|
||||
"title": "HLL_UNION_AGG",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
46
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/max.md
Executable file
46
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/max.md
Executable file
@ -0,0 +1,46 @@
|
||||
---
|
||||
{
|
||||
"title": "MAX",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# MAX
|
||||
## description
|
||||
### Syntax
|
||||
|
||||
`MAX(expr)`
|
||||
|
||||
|
||||
返回expr表达式的最大值
|
||||
|
||||
## example
|
||||
```
|
||||
MySQL > select max(scan_rows) from log_statis group by datetime;
|
||||
+------------------+
|
||||
| max(`scan_rows`) |
|
||||
+------------------+
|
||||
| 4671587 |
|
||||
+------------------+
|
||||
```
|
||||
## keyword
|
||||
MAX
|
||||
46
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/min.md
Executable file
46
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/min.md
Executable file
@ -0,0 +1,46 @@
|
||||
---
|
||||
{
|
||||
"title": "MIN",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# MIN
|
||||
## description
|
||||
### Syntax
|
||||
|
||||
`MIN(expr)`
|
||||
|
||||
|
||||
返回expr表达式的最小值
|
||||
|
||||
## example
|
||||
```
|
||||
MySQL > select min(scan_rows) from log_statis group by datetime;
|
||||
+------------------+
|
||||
| min(`scan_rows`) |
|
||||
+------------------+
|
||||
| 0 |
|
||||
+------------------+
|
||||
```
|
||||
## keyword
|
||||
MIN
|
||||
57
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/percentile.md
Executable file
57
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/percentile.md
Executable file
@ -0,0 +1,57 @@
|
||||
---
|
||||
{
|
||||
"title": "PERCENTILE",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,59 @@
|
||||
---
|
||||
{
|
||||
"title": "PERCENTILE_APPROX",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
53
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/stddev.md
Executable file
53
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/stddev.md
Executable file
@ -0,0 +1,53 @@
|
||||
---
|
||||
{
|
||||
"title": "STDDEV,STDDEV_POP",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
46
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/stddev_samp.md
Executable file
46
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/stddev_samp.md
Executable file
@ -0,0 +1,46 @@
|
||||
---
|
||||
{
|
||||
"title": "STDDEV_SAMP",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
46
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/sum.md
Executable file
46
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/sum.md
Executable file
@ -0,0 +1,46 @@
|
||||
---
|
||||
{
|
||||
"title": "SUM",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# SUM
|
||||
## description
|
||||
### Syntax
|
||||
|
||||
`SUM(expr)`
|
||||
|
||||
|
||||
用于返回选中字段所有值的和
|
||||
|
||||
## example
|
||||
```
|
||||
MySQL > select sum(scan_rows) from log_statis group by datetime;
|
||||
+------------------+
|
||||
| sum(`scan_rows`) |
|
||||
+------------------+
|
||||
| 8217360135 |
|
||||
+------------------+
|
||||
```
|
||||
## keyword
|
||||
SUM
|
||||
@ -0,0 +1,60 @@
|
||||
---
|
||||
{
|
||||
"title": "TOPN",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
47
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/var_samp.md
Executable file
47
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/var_samp.md
Executable file
@ -0,0 +1,47 @@
|
||||
---
|
||||
{
|
||||
"title": "VAR_SAMP,VARIANCE_SAMP",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
54
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/variance.md
Executable file
54
new-docs/zh-CN/sql-manual/sql-functions/aggregate-functions/variance.md
Executable file
@ -0,0 +1,54 @@
|
||||
---
|
||||
{
|
||||
"title": "VARIANCE,VAR_POP,VARIANCE_POP",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,83 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_and",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,84 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_and_count",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,48 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_and_not",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,48 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_and_not_count",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_contains",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,52 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_empty",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,63 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_from_string",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,56 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_has_all",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_has_any",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,52 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_hash",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,62 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_intersect",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_max",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_min",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_not",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,83 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_or",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,77 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_or_count",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,57 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_subset_in_range",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,59 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_subset_limit",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,69 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_to_string",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,59 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_union",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,76 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_xor",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,84 @@
|
||||
---
|
||||
{
|
||||
"title": "bitmap_xor_count",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
---
|
||||
{
|
||||
"title": "orthogonal_bitmap_intersect",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,46 @@
|
||||
---
|
||||
{
|
||||
"title": "orthogonal_bitmap_intersect_count",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,47 @@
|
||||
---
|
||||
{
|
||||
"title": "orthogonal_bitmap_union_count",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,62 @@
|
||||
---
|
||||
{
|
||||
"title": "sub_bitmap",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,61 @@
|
||||
---
|
||||
{
|
||||
"title": "to_bitmap",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,57 @@
|
||||
---
|
||||
{
|
||||
"title": "bitand",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,57 @@
|
||||
---
|
||||
{
|
||||
"title": "bitnot",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,57 @@
|
||||
---
|
||||
{
|
||||
"title": "bitor",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,57 @@
|
||||
---
|
||||
{
|
||||
"title": "bitxor",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -24,4 +24,59 @@ specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
# CAST
|
||||
# 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
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
---
|
||||
{
|
||||
"title": "case",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,47 @@
|
||||
---
|
||||
{
|
||||
"title": "coalesce",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# coalesce
|
||||
## description
|
||||
### Syntax
|
||||
|
||||
`coalesce(expr1, expr2, ...., expr_n))`
|
||||
|
||||
返回参数中的第一个非空表达式(从左向右)
|
||||
|
||||
## example
|
||||
|
||||
```
|
||||
mysql> select coalesce(NULL, '1111', '0000');
|
||||
+--------------------------------+
|
||||
| coalesce(NULL, '1111', '0000') |
|
||||
+--------------------------------+
|
||||
| 1111 |
|
||||
+--------------------------------+
|
||||
```
|
||||
## keyword
|
||||
|
||||
COALESCE
|
||||
@ -0,0 +1,50 @@
|
||||
---
|
||||
{
|
||||
"title": "if",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,54 @@
|
||||
---
|
||||
{
|
||||
"title": "ifnull",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,61 @@
|
||||
---
|
||||
{
|
||||
"title": "nullif",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "convert_tz",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "curdate,current_date",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,49 @@
|
||||
---
|
||||
{
|
||||
"title": "current_timestamp",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,50 @@
|
||||
---
|
||||
{
|
||||
"title": "curtime,current_time",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# curtime,current_time
|
||||
|
||||
## Syntax
|
||||
|
||||
`TIME CURTIME()`
|
||||
|
||||
## Description
|
||||
|
||||
获得当前的时间,以TIME类型返回
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
mysql> select current_time();
|
||||
+----------------+
|
||||
| current_time() |
|
||||
+----------------+
|
||||
| 15:25:47 |
|
||||
+----------------+
|
||||
```
|
||||
|
||||
## keyword
|
||||
|
||||
CURTIME,CURRENT_TIME
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "date_add",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,168 @@
|
||||
---
|
||||
{
|
||||
"title": "date_format",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,55 @@
|
||||
---
|
||||
{
|
||||
"title": "date_sub",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,58 @@
|
||||
---
|
||||
{
|
||||
"title": "datediff",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,49 @@
|
||||
---
|
||||
{
|
||||
"title": "day",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,50 @@
|
||||
---
|
||||
{
|
||||
"title": "dayname",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,51 @@
|
||||
---
|
||||
{
|
||||
"title": "dayofmonth",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,58 @@
|
||||
---
|
||||
{
|
||||
"title": "dayofweek",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,51 @@
|
||||
---
|
||||
{
|
||||
"title": "dayofyear",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,49 @@
|
||||
---
|
||||
{
|
||||
"title": "from_days",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,80 @@
|
||||
---
|
||||
{
|
||||
"title": "from_unixtime",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,49 @@
|
||||
---
|
||||
{
|
||||
"title": "hour",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,46 @@
|
||||
---
|
||||
{
|
||||
"title": "makedate",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,49 @@
|
||||
---
|
||||
{
|
||||
"title": "minute",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,51 @@
|
||||
---
|
||||
{
|
||||
"title": "month",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,51 @@
|
||||
---
|
||||
{
|
||||
"title": "monthname",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,49 @@
|
||||
---
|
||||
{
|
||||
"title": "now",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# now
|
||||
## description
|
||||
### Syntax
|
||||
|
||||
`DATETIME NOW()`
|
||||
|
||||
|
||||
获得当前的时间,以Datetime类型返回
|
||||
|
||||
## example
|
||||
|
||||
```
|
||||
mysql> select now();
|
||||
+---------------------+
|
||||
| now() |
|
||||
+---------------------+
|
||||
| 2019-05-27 15:58:25 |
|
||||
+---------------------+
|
||||
```
|
||||
|
||||
## keyword
|
||||
|
||||
NOW
|
||||
@ -0,0 +1,49 @@
|
||||
---
|
||||
{
|
||||
"title": "second",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,72 @@
|
||||
---
|
||||
{
|
||||
"title": "str_to_date",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,86 @@
|
||||
---
|
||||
{
|
||||
"title": "time_round",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,65 @@
|
||||
---
|
||||
{
|
||||
"title": "timediff",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,59 @@
|
||||
---
|
||||
{
|
||||
"title": "timestampadd",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,67 @@
|
||||
---
|
||||
{
|
||||
"title": "timestampdiff",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,48 @@
|
||||
---
|
||||
{
|
||||
"title": "to_date",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,51 @@
|
||||
---
|
||||
{
|
||||
"title": "to_days",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,86 @@
|
||||
---
|
||||
{
|
||||
"title": "unix_timestamp",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,53 @@
|
||||
---
|
||||
{
|
||||
"title": "utc_timestamp",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,68 @@
|
||||
---
|
||||
{
|
||||
"title": "week",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,68 @@
|
||||
---
|
||||
{
|
||||
"title": "weekday",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,52 @@
|
||||
---
|
||||
{
|
||||
"title": "weekofyear",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,51 @@
|
||||
---
|
||||
{
|
||||
"title": "year",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,80 @@
|
||||
---
|
||||
{
|
||||
"title": "yearweek",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -24,4 +24,33 @@ specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
# DIGITAL_MASKING
|
||||
# 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
|
||||
|
||||
@ -0,0 +1,93 @@
|
||||
---
|
||||
{
|
||||
"title": "AES",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,47 @@
|
||||
---
|
||||
{
|
||||
"title": "MD5",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,56 @@
|
||||
---
|
||||
{
|
||||
"title": "MD5SUM",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,47 @@
|
||||
---
|
||||
{
|
||||
"title": "SM3",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,56 @@
|
||||
---
|
||||
{
|
||||
"title": "SM3SUM",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
@ -0,0 +1,93 @@
|
||||
---
|
||||
{
|
||||
"title": "SM4",
|
||||
"language": "zh-CN"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
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.
|
||||
-->
|
||||
|
||||
# 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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user