This is an automated email from the ASF dual-hosted git repository. kassiez pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push: new b386b2af5d3 [Doc]positive round round_bankers sign sin (#1991) b386b2af5d3 is described below commit b386b2af5d3cddadc4c1cca658df11800946bf2e Author: xiaozhuoyang <98680833+xiaozhuoy...@users.noreply.github.com> AuthorDate: Wed Feb 12 11:32:04 2025 +0800 [Doc]positive round round_bankers sign sin (#1991) ## Versions - [x] dev - [x] 3.0 - [x] 2.1 - [ ] 2.0 ## Languages - [x] Chinese - [x] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built --------- Signed-off-by: leozhuo <961937...@qq.com> --- .../scalar-functions/numeric-functions/positive.md | 64 ++++++++-- .../numeric-functions/round-bankers.md | 134 ++++++++++++++++----- .../scalar-functions/numeric-functions/round.md | 8 +- .../scalar-functions/numeric-functions/sign.md | 104 +++++++++++----- .../scalar-functions/numeric-functions/positive.md | 60 +++++++-- .../numeric-functions/round-bankers.md | 129 +++++++++++++++----- .../scalar-functions/numeric-functions/round.md | 8 +- .../scalar-functions/numeric-functions/sign.md | 96 +++++++++++---- .../scalar-functions/numeric-functions/sin.md | 18 +++ .../scalar-functions/numeric-functions/positive.md | 60 +++++++-- .../numeric-functions/round-bankers.md | 129 +++++++++++++++----- .../scalar-functions/numeric-functions/round.md | 8 +- .../scalar-functions/numeric-functions/sign.md | 96 +++++++++++---- .../scalar-functions/numeric-functions/sin.md | 18 +++ .../scalar-functions/numeric-functions/positive.md | 60 +++++++-- .../numeric-functions/round-bankers.md | 129 +++++++++++++++----- .../scalar-functions/numeric-functions/round.md | 8 +- .../scalar-functions/numeric-functions/sign.md | 96 +++++++++++---- .../scalar-functions/numeric-functions/sin.md | 18 +++ .../scalar-functions/numeric-functions/positive.md | 64 ++++++++-- .../numeric-functions/round-bankers.md | 134 ++++++++++++++++----- .../scalar-functions/numeric-functions/round.md | 8 +- .../scalar-functions/numeric-functions/sign.md | 104 +++++++++++----- .../scalar-functions/numeric-functions/positive.md | 64 ++++++++-- .../numeric-functions/round-bankers.md | 134 ++++++++++++++++----- .../scalar-functions/numeric-functions/round.md | 8 +- .../scalar-functions/numeric-functions/sign.md | 104 +++++++++++----- 27 files changed, 1446 insertions(+), 417 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md index 952e1a9101f..1422e235a31 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md @@ -22,28 +22,59 @@ specific language governing permissions and limitations under the License. --> -## positive +## Description -### description -#### Syntax +Returns the value itself. + +## Syntax ```sql -BIGINT positive(BIGINT x) -DOUBLE positive(DOUBLE x) -DECIMAL positive(DECIMAL x) +POSITIVE(<x>) ``` -Return `x`. -### example +## Parameters + +| Parameter | Description | +|-----------|------------| +| `<x>` | The value that needs to be returned. | + +## Return value + +Returns an integer or a floating-point number. Special cases: + +- If the parameter is NULL, return NULL. + +## Example +```sql +SELECT positive(-10); ``` -mysql> SELECT positive(-10); + +```text +---------------+ | positive(-10) | +---------------+ | -10 | +---------------+ -mysql> SELECT positive(12); +``` + +```sql +SELECT positive(10.111); +``` + +```text ++------------------+ +| positive(10.111) | ++------------------+ +| 10.111 | ++------------------+ +``` + +```sql +SELECT positive(12); +``` + +```text +--------------+ | positive(12) | +--------------+ @@ -51,5 +82,14 @@ mysql> SELECT positive(12); +--------------+ ``` -### keywords - POSITIVE +```sql +SELECT positive(null); +``` + +```text ++----------------+ +| positive(NULL) | ++----------------+ +| NULL | ++----------------+ +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md index 454cf67bb02..ae7c0d52b94 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md @@ -22,73 +22,145 @@ specific language governing permissions and limitations under the License. --> -## round_bankers +## Description -### description -#### Syntax +Round x using the banker's rounding method and keep d decimal places. The default value of d is 0. -`T round_bankers(T x[, d])` -Rounds the argument `x` to `d` specified decimal places. `d` defaults to 0 if not specified. If d is negative, the left d digits of the decimal point are 0. If x or d is null, null is returned. +If d is negative, the |d| digits to the left of the decimal point will be set to 0. -If `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +If x or d is null, return null. -+ If the rounding number is halfway between two numbers, the function uses banker’s rounding. -+ In other cases, the function rounds numbers to the nearest integer. +If d represents a column and the first parameter is of the Decimal type, then the resulting Decimal will have the same number of decimal places as the input Decimal. +According to the rules of the banker's rounding algorithm, when rounding to a specified decimal place: +- If the digit to be rounded is 5 and there are no other non - zero digits following it, the digit immediately preceding it will be checked: + - If the preceding digit is even, the 5 will be simply dropped. + - If the preceding digit is odd, the number will be rounded up. -### example +- If the digit to be rounded is greater than 5 or there are non - zero digits following it, the traditional rounding rules will apply: round up if the digit is greater than or equal to 5, otherwise round down. +For example: + +- For the value 2.5, since the digit 2 before 5 is even, the result will be rounded to 2. + +- For the value 3.5, since the digit 3 before 5 is odd, the result will be rounded to 4. + +- For the value 2.51, since the digit after 5 is not 0, it will be rounded up directly, and the result is 3. + +## Syntax + +```sql +ROUND_BANKERS(<x> [ , <d>]) ``` -mysql> select round_bankers(0.4); + +## Parameters + +| Parameter | Description | +|-----------|------------| +| `<x>` | The number to be rounded | +| `<d>` | Optional, the number of decimal places to round to, with a default value of 0. | + +## Return value + +Returns an integer or a float-point number: + +- By default, when the parameter d = 0, it returns an integer obtained by calculating x using the banker's rounding algorithm. + +- If d is negative, it returns an integer with the first digit to the left of the decimal point being 0. + +- If both x and d are NULL, it returns NULL. + +- If d represents a column and x is of the Decimal type, it returns a floating-point number with the same precision. + +## Example + +```sql +select round_bankers(0.4); +``` + +```text +--------------------+ | round_bankers(0.4) | +--------------------+ | 0 | +--------------------+ -mysql> select round_bankers(-3.5); +``` + +```sql +select round_bankers(-3.5); +``` + +```text +---------------------+ | round_bankers(-3.5) | +---------------------+ | -4 | +---------------------+ -mysql> select round_bankers(-3.4); +``` + +```sql +select round_bankers(-3.4); +``` + +```text +---------------------+ | round_bankers(-3.4) | +---------------------+ | -3 | +---------------------+ -mysql> select round_bankers(10.755, 2); +``` + +```sql +select round_bankers(10.755, 2); +``` + +```text +--------------------------+ | round_bankers(10.755, 2) | +--------------------------+ | 10.76 | +--------------------------+ -mysql> select round_bankers(1667.2725, 2); -+-----------------------------+ -| round_bankers(1667.2725, 2) | -+-----------------------------+ -| 1667.27 | -+-----------------------------+ -mysql> select round_bankers(1667.2725, -2); +``` + +```sql +select round_bankers(10.745, 2); +``` + +```text ++--------------------------+ +| round_bankers(10.745, 2) | ++--------------------------+ +| 10.74 | ++--------------------------+ +``` + +```sql +select round_bankers(1667.2725, -2); +``` + +```text +------------------------------+ | round_bankers(1667.2725, -2) | +------------------------------+ | 1700 | +------------------------------+ -mysql> SELECT number - -> , round_bankers(number * 2.5, number - 1) AS rb_decimal_column - -> , round_bankers(number * 2.5, 0) AS rb_decimal_literal - -> , round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column - -> , round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; +``` + +```sql +SELECT number +, round_bankers(number * 2.5, number - 1) AS rb_decimal_column +, round_bankers(number * 2.5, 0) AS rb_decimal_literal +, round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column +, round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal +FROM test_enhanced_round +WHERE rid = 1; +``` + +```text +--------+-------------------+--------------------+------------------+-------------------+ | number | rb_decimal_column | rb_decimal_literal | rb_double_column | rb_double_literal | +--------+-------------------+--------------------+------------------+-------------------+ | 1 | 2.0 | 2 | 2 | 2 | +--------+-------------------+--------------------+------------------+-------------------+ -``` - -### keywords - round_bankers +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md index 53840b55c51..00851fab629 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md @@ -53,6 +53,7 @@ ROUND(<x> [ , <d> ]) ```sql select round(2.4); ``` + ```text +------------+ | round(2.4) | @@ -64,6 +65,7 @@ select round(2.4); ```sql select round(2.5); ``` + ```text +------------+ | round(2.5) | @@ -75,6 +77,7 @@ select round(2.5); ```sql select round(-3.4); ``` + ```text +-------------+ | round(-3.4) | @@ -86,6 +89,7 @@ select round(-3.4); ```sql select round(-3.5); ``` + ```text +-------------+ | round(-3.5) | @@ -97,6 +101,7 @@ select round(-3.5); ```sql select round(1667.2725, 2); ``` + ```text +---------------------+ | round(1667.2725, 2) | @@ -108,6 +113,7 @@ select round(1667.2725, 2); ```sql select round(1667.2725, -2); ``` + ```text +----------------------+ | round(1667.2725, -2) | @@ -143,4 +149,4 @@ SELECT number, dec90, round(dec90, number), dec91, round(dec91, number), dec99, ``` ## Usage Note -2.5 will round to 3. If you want to round to 2, use the `round_bankers` function. \ No newline at end of file +2.5 will round to 3. If you want to round to 2, use the `round_bankers` function. diff --git a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md index 4f98136466e..90bbee6ca7e 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md +++ b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md @@ -22,36 +22,80 @@ specific language governing permissions and limitations under the License. --> -## sign +## Description -### description -#### Syntax - -`TINYINT sign(DOUBLE x)` Returns the sign of `x`. Negative, zero or positive numbers correspond to -1, 0 or 1 respectively. -### example - -``` -mysql> select sign(3); -+-----------+ -| sign(3.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select sign(0); -+-----------+ -| sign(0.0) | -+-----------+ -| 0 | -mysql> select sign(-10.0); -+-------------+ -| sign(-10.0) | -+-------------+ -| -1 | -+-------------+ -1 row in set (0.01 sec) -``` - -### keywords - SIGN +## Syntax + +```sql +SIGN(x) +``` + +## Parameters + +| Parameter | Description | +|-----------|------------| +| `<x>` | independent variable | + +## Return value + +Returns an integer: + +- If x > 0, it returns 1, representing a positive number. + +- If x = 0, it returns 0, representing zero. + +- If x < 0, it returns -1, representing a negative number. + +- If x is NULL, it returns NULL. + +## Example + +```sql +select sign(3); +``` + +```text ++-------------------------+ +| sign(cast(3 as DOUBLE)) | ++-------------------------+ +| 1 | ++-------------------------+ +``` + +```sql +select sign(0); +``` + +```text ++-------------------------+ +| sign(cast(0 as DOUBLE)) | ++-------------------------+ +| 0 | ++-------------------------+ +``` + +```sql +select sign(-10.0); +``` + +```text ++-----------------------------+ +| sign(cast(-10.0 as DOUBLE)) | ++-----------------------------+ +| -1 | ++-----------------------------+ +``` + +```sql +select sign(null); +``` + +```text ++------------+ +| sign(NULL) | ++------------+ +| NULL | ++------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md index e7e7352fb16..126dfa5b7b3 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md @@ -22,28 +22,59 @@ specific language governing permissions and limitations under the License. --> -## positive - ## 描述 + +返回数值本身。 + ## 语法 ```sql -BIGINT positive(BIGINT x) -DOUBLE positive(DOUBLE x) -DECIMAL positive(DECIMAL x) +POSITIVE(<x>) ``` -返回`x`. + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要返回的数值 | + +## 返回值 + +返回一个整型或者浮点数。特殊情况: + +- 当x is NULL 时,返回 NULL ## 举例 +```sql +SELECT positive(-10); ``` -mysql> SELECT positive(-10); + +```text +---------------+ | positive(-10) | +---------------+ | -10 | +---------------+ -mysql> SELECT positive(12); +``` + +```sql +SELECT positive(10.111); +``` + +```text ++------------------+ +| positive(10.111) | ++------------------+ +| 10.111 | ++------------------+ +``` + +```sql +SELECT positive(12); +``` + +```text +--------------+ | positive(12) | +--------------+ @@ -51,5 +82,14 @@ mysql> SELECT positive(12); +--------------+ ``` -### keywords - POSITIVE +```sql +SELECT positive(null); +``` + +```text ++----------------+ +| positive(NULL) | ++----------------+ +| NULL | ++----------------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md index 6b63ba92906..96c2012ab1b 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md @@ -22,72 +22,145 @@ specific language governing permissions and limitations under the License. --> -## round_bankers - ## 描述 -## 语法 -`T round_bankers(T x[, d])` -将`x`使用银行家舍入法后,保留d位小数,`d`默认为0。如果`d`为负数,则小数点左边`d`位为0。如果`x`或`d`为null,返回null。 +将`x`使用银行家舍入法后,保留d位小数,`d`默认为0。 + +如果`d`为负数,则小数点左边`d`位为0。 + +如果`x`或`d`为null,返回null。 如果 d 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 -+ 如果舍入数介于两个数字之间,则该函数使用银行家的舍入 -+ 在其他情况下,该函数将数字四舍五入到最接近的整数。 +根据银行家舍入算法的规则,当需要舍入到指定的小数位时: + +- 如果要舍入的数字是5,且后面没有其他非零数字,则会检查前一位数字: + - 如果前一位数字是偶数,则直接舍去; + - 如果前一位数字是奇数,则向上进一。 + +- 如果要舍入的数字大于5或者其后有非0的数字,则按照传统的四舍五入规则进行:即大于等于5则进位,否则舍去。 + +例如: +- 对于数值2.5,由于5前面的数字2是偶数,因此结果将舍入为2。 + +- 对于数值3.5,由于5前面的数字3是奇数,因此结果将舍入为4。 + +- 对于数值2.51,因为5后面的数字不是0,所以直接进位,结果为3。 + +## 语法 + +```sql +ROUND_BANKERS(<x> [ , <d>]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要四舍五入的数值 | +| `<d>` | 可选,四舍五入需要保留的小数位数,默认为0 | + +## 返回值 + +返回一个整型或者浮点数: + +- 默认情况,参数d = 0 , 返回 `x` 根据银行家舍入算法计算过的整数。 + +- d 为 负数 , 返回小数点左边第一位为0的整数。 + +- x 和 d is NULL , 返回NULL。 + +- d 为一个列时 , 且 `x` 为Decimal类型 , 返回相同精度的浮点数。 ## 举例 +```sql +select round_bankers(0.4); ``` -mysql> select round_bankers(0.4); + +```text +--------------------+ | round_bankers(0.4) | +--------------------+ | 0 | +--------------------+ -mysql> select round_bankers(-3.5); +``` + +```sql +select round_bankers(-3.5); +``` + +```text +---------------------+ | round_bankers(-3.5) | +---------------------+ | -4 | +---------------------+ -mysql> select round_bankers(-3.4); +``` + +```sql +select round_bankers(-3.4); +``` + +```text +---------------------+ | round_bankers(-3.4) | +---------------------+ | -3 | +---------------------+ -mysql> select round_bankers(10.755, 2); +``` + +```sql +select round_bankers(10.755, 2); +``` + +```text +--------------------------+ | round_bankers(10.755, 2) | +--------------------------+ | 10.76 | +--------------------------+ -mysql> select round_bankers(1667.2725, 2); -+-----------------------------+ -| round_bankers(1667.2725, 2) | -+-----------------------------+ -| 1667.27 | -+-----------------------------+ -mysql> select round_bankers(1667.2725, -2); +``` + +```sql +select round_bankers(10.745, 2); +``` + +```text ++--------------------------+ +| round_bankers(10.745, 2) | ++--------------------------+ +| 10.74 | ++--------------------------+ +``` + +```sql +select round_bankers(1667.2725, -2); +``` + +```text +------------------------------+ | round_bankers(1667.2725, -2) | +------------------------------+ | 1700 | +------------------------------+ -mysql> SELECT number - -> , round_bankers(number * 2.5, number - 1) AS rb_decimal_column - -> , round_bankers(number * 2.5, 0) AS rb_decimal_literal - -> , round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column - -> , round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; +``` + +```sql +SELECT number +, round_bankers(number * 2.5, number - 1) AS rb_decimal_column +, round_bankers(number * 2.5, 0) AS rb_decimal_literal +, round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column +, round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal +FROM test_enhanced_round +WHERE rid = 1; +``` + +```text +--------+-------------------+--------------------+------------------+-------------------+ | number | rb_decimal_column | rb_decimal_literal | rb_double_column | rb_double_literal | +--------+-------------------+--------------------+------------------+-------------------+ | 1 | 2.0 | 2 | 2 | 2 | +--------+-------------------+--------------------+------------------+-------------------+ ``` - -### keywords - round_bankers diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md index 3b1853255d6..3737123a427 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md @@ -51,6 +51,7 @@ ROUND(<x> [ , <d> ]) ```sql select round(2.4); ``` + ```text +------------+ | round(2.4) | @@ -62,6 +63,7 @@ select round(2.4); ```sql select round(2.5); ``` + ```text +------------+ | round(2.5) | @@ -73,6 +75,7 @@ select round(2.5); ```sql select round(-3.4); ``` + ```text +-------------+ | round(-3.4) | @@ -84,6 +87,7 @@ select round(-3.4); ```sql select round(-3.5); ``` + ```text +-------------+ | round(-3.5) | @@ -95,6 +99,7 @@ select round(-3.5); ```sql select round(1667.2725, 2); ``` + ```text +---------------------+ | round(1667.2725, 2) | @@ -106,6 +111,7 @@ select round(1667.2725, 2); ```sql select round(1667.2725, -2); ``` + ```text +----------------------+ | round(1667.2725, -2) | @@ -141,4 +147,4 @@ SELECT number, dec90, round(dec90, number), dec91, round(dec91, number), dec99, ``` ## 注意事项 -2.5 会舍入到 3,如果想要舍入到 2 的算法,请使用 `round_bankers` 函数。 \ No newline at end of file +2.5 会舍入到 3,如果想要舍入到 2 的算法,请使用 `round_bankers` 函数。 diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md index 251f5060c03..089f3ce8c51 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md @@ -22,36 +22,80 @@ specific language governing permissions and limitations under the License. --> -## sign - ## 描述 + +返回`x`的符号。负数,零或正数分别对应-1,0或1。 + ## 语法 -`TINYINT sign(DOUBLE x)` -返回`x`的符号.负数,零或正数分别对应-1,0或1. +```sql +SIGN(x) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 自变量 | + +## 返回值 + +返回一个整型: + +- 当 x > 0 时,返回 1,代表整数。 + +- 当 x = 0 时,返回 0,代表零。 + +- 当 x < 0 时,返回 -1,代表负数。 + +- 当 x is NULL时,返回 NULL。 ## 举例 +```sql +select sign(3); ``` -mysql> select sign(3); -+-----------+ -| sign(3.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select sign(0); -+-----------+ -| sign(0.0) | -+-----------+ -| 0 | -mysql> select sign(-10.0); -+-------------+ -| sign(-10.0) | -+-------------+ -| -1 | -+-------------+ -1 row in set (0.01 sec) -``` - -### keywords - SIGN + +```text ++-------------------------+ +| sign(cast(3 as DOUBLE)) | ++-------------------------+ +| 1 | ++-------------------------+ +``` + +```sql +select sign(0); +``` + +```text ++-------------------------+ +| sign(cast(0 as DOUBLE)) | ++-------------------------+ +| 0 | ++-------------------------+ +``` + +```sql +select sign(-10.0); +``` + +```text ++-----------------------------+ +| sign(cast(-10.0 as DOUBLE)) | ++-----------------------------+ +| -1 | ++-----------------------------+ +``` + +```sql +select sign(null); +``` + +```text ++------------+ +| sign(NULL) | ++------------+ +| NULL | ++------------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md index a98e2eece7e..8b8159bb008 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md @@ -42,6 +42,24 @@ SIN(<a>) 参数 `<a>` 的正弦值,弧度制表示。 +## 语法 + +```sql +SIN(<x>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 弧度值 | + +## 返回值 + +返回浮点数。特殊情况: + +- 当 x is NULL 时,返回 NULL. + ## 举例 ```sql diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md index e7e7352fb16..126dfa5b7b3 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md @@ -22,28 +22,59 @@ specific language governing permissions and limitations under the License. --> -## positive - ## 描述 + +返回数值本身。 + ## 语法 ```sql -BIGINT positive(BIGINT x) -DOUBLE positive(DOUBLE x) -DECIMAL positive(DECIMAL x) +POSITIVE(<x>) ``` -返回`x`. + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要返回的数值 | + +## 返回值 + +返回一个整型或者浮点数。特殊情况: + +- 当x is NULL 时,返回 NULL ## 举例 +```sql +SELECT positive(-10); ``` -mysql> SELECT positive(-10); + +```text +---------------+ | positive(-10) | +---------------+ | -10 | +---------------+ -mysql> SELECT positive(12); +``` + +```sql +SELECT positive(10.111); +``` + +```text ++------------------+ +| positive(10.111) | ++------------------+ +| 10.111 | ++------------------+ +``` + +```sql +SELECT positive(12); +``` + +```text +--------------+ | positive(12) | +--------------+ @@ -51,5 +82,14 @@ mysql> SELECT positive(12); +--------------+ ``` -### keywords - POSITIVE +```sql +SELECT positive(null); +``` + +```text ++----------------+ +| positive(NULL) | ++----------------+ +| NULL | ++----------------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md index 6b63ba92906..96c2012ab1b 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md @@ -22,72 +22,145 @@ specific language governing permissions and limitations under the License. --> -## round_bankers - ## 描述 -## 语法 -`T round_bankers(T x[, d])` -将`x`使用银行家舍入法后,保留d位小数,`d`默认为0。如果`d`为负数,则小数点左边`d`位为0。如果`x`或`d`为null,返回null。 +将`x`使用银行家舍入法后,保留d位小数,`d`默认为0。 + +如果`d`为负数,则小数点左边`d`位为0。 + +如果`x`或`d`为null,返回null。 如果 d 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 -+ 如果舍入数介于两个数字之间,则该函数使用银行家的舍入 -+ 在其他情况下,该函数将数字四舍五入到最接近的整数。 +根据银行家舍入算法的规则,当需要舍入到指定的小数位时: + +- 如果要舍入的数字是5,且后面没有其他非零数字,则会检查前一位数字: + - 如果前一位数字是偶数,则直接舍去; + - 如果前一位数字是奇数,则向上进一。 + +- 如果要舍入的数字大于5或者其后有非0的数字,则按照传统的四舍五入规则进行:即大于等于5则进位,否则舍去。 + +例如: +- 对于数值2.5,由于5前面的数字2是偶数,因此结果将舍入为2。 + +- 对于数值3.5,由于5前面的数字3是奇数,因此结果将舍入为4。 + +- 对于数值2.51,因为5后面的数字不是0,所以直接进位,结果为3。 + +## 语法 + +```sql +ROUND_BANKERS(<x> [ , <d>]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要四舍五入的数值 | +| `<d>` | 可选,四舍五入需要保留的小数位数,默认为0 | + +## 返回值 + +返回一个整型或者浮点数: + +- 默认情况,参数d = 0 , 返回 `x` 根据银行家舍入算法计算过的整数。 + +- d 为 负数 , 返回小数点左边第一位为0的整数。 + +- x 和 d is NULL , 返回NULL。 + +- d 为一个列时 , 且 `x` 为Decimal类型 , 返回相同精度的浮点数。 ## 举例 +```sql +select round_bankers(0.4); ``` -mysql> select round_bankers(0.4); + +```text +--------------------+ | round_bankers(0.4) | +--------------------+ | 0 | +--------------------+ -mysql> select round_bankers(-3.5); +``` + +```sql +select round_bankers(-3.5); +``` + +```text +---------------------+ | round_bankers(-3.5) | +---------------------+ | -4 | +---------------------+ -mysql> select round_bankers(-3.4); +``` + +```sql +select round_bankers(-3.4); +``` + +```text +---------------------+ | round_bankers(-3.4) | +---------------------+ | -3 | +---------------------+ -mysql> select round_bankers(10.755, 2); +``` + +```sql +select round_bankers(10.755, 2); +``` + +```text +--------------------------+ | round_bankers(10.755, 2) | +--------------------------+ | 10.76 | +--------------------------+ -mysql> select round_bankers(1667.2725, 2); -+-----------------------------+ -| round_bankers(1667.2725, 2) | -+-----------------------------+ -| 1667.27 | -+-----------------------------+ -mysql> select round_bankers(1667.2725, -2); +``` + +```sql +select round_bankers(10.745, 2); +``` + +```text ++--------------------------+ +| round_bankers(10.745, 2) | ++--------------------------+ +| 10.74 | ++--------------------------+ +``` + +```sql +select round_bankers(1667.2725, -2); +``` + +```text +------------------------------+ | round_bankers(1667.2725, -2) | +------------------------------+ | 1700 | +------------------------------+ -mysql> SELECT number - -> , round_bankers(number * 2.5, number - 1) AS rb_decimal_column - -> , round_bankers(number * 2.5, 0) AS rb_decimal_literal - -> , round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column - -> , round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; +``` + +```sql +SELECT number +, round_bankers(number * 2.5, number - 1) AS rb_decimal_column +, round_bankers(number * 2.5, 0) AS rb_decimal_literal +, round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column +, round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal +FROM test_enhanced_round +WHERE rid = 1; +``` + +```text +--------+-------------------+--------------------+------------------+-------------------+ | number | rb_decimal_column | rb_decimal_literal | rb_double_column | rb_double_literal | +--------+-------------------+--------------------+------------------+-------------------+ | 1 | 2.0 | 2 | 2 | 2 | +--------+-------------------+--------------------+------------------+-------------------+ ``` - -### keywords - round_bankers diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md index 3b1853255d6..3737123a427 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md @@ -51,6 +51,7 @@ ROUND(<x> [ , <d> ]) ```sql select round(2.4); ``` + ```text +------------+ | round(2.4) | @@ -62,6 +63,7 @@ select round(2.4); ```sql select round(2.5); ``` + ```text +------------+ | round(2.5) | @@ -73,6 +75,7 @@ select round(2.5); ```sql select round(-3.4); ``` + ```text +-------------+ | round(-3.4) | @@ -84,6 +87,7 @@ select round(-3.4); ```sql select round(-3.5); ``` + ```text +-------------+ | round(-3.5) | @@ -95,6 +99,7 @@ select round(-3.5); ```sql select round(1667.2725, 2); ``` + ```text +---------------------+ | round(1667.2725, 2) | @@ -106,6 +111,7 @@ select round(1667.2725, 2); ```sql select round(1667.2725, -2); ``` + ```text +----------------------+ | round(1667.2725, -2) | @@ -141,4 +147,4 @@ SELECT number, dec90, round(dec90, number), dec91, round(dec91, number), dec99, ``` ## 注意事项 -2.5 会舍入到 3,如果想要舍入到 2 的算法,请使用 `round_bankers` 函数。 \ No newline at end of file +2.5 会舍入到 3,如果想要舍入到 2 的算法,请使用 `round_bankers` 函数。 diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md index 251f5060c03..089f3ce8c51 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md @@ -22,36 +22,80 @@ specific language governing permissions and limitations under the License. --> -## sign - ## 描述 + +返回`x`的符号。负数,零或正数分别对应-1,0或1。 + ## 语法 -`TINYINT sign(DOUBLE x)` -返回`x`的符号.负数,零或正数分别对应-1,0或1. +```sql +SIGN(x) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 自变量 | + +## 返回值 + +返回一个整型: + +- 当 x > 0 时,返回 1,代表整数。 + +- 当 x = 0 时,返回 0,代表零。 + +- 当 x < 0 时,返回 -1,代表负数。 + +- 当 x is NULL时,返回 NULL。 ## 举例 +```sql +select sign(3); ``` -mysql> select sign(3); -+-----------+ -| sign(3.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select sign(0); -+-----------+ -| sign(0.0) | -+-----------+ -| 0 | -mysql> select sign(-10.0); -+-------------+ -| sign(-10.0) | -+-------------+ -| -1 | -+-------------+ -1 row in set (0.01 sec) -``` - -### keywords - SIGN + +```text ++-------------------------+ +| sign(cast(3 as DOUBLE)) | ++-------------------------+ +| 1 | ++-------------------------+ +``` + +```sql +select sign(0); +``` + +```text ++-------------------------+ +| sign(cast(0 as DOUBLE)) | ++-------------------------+ +| 0 | ++-------------------------+ +``` + +```sql +select sign(-10.0); +``` + +```text ++-----------------------------+ +| sign(cast(-10.0 as DOUBLE)) | ++-----------------------------+ +| -1 | ++-----------------------------+ +``` + +```sql +select sign(null); +``` + +```text ++------------+ +| sign(NULL) | ++------------+ +| NULL | ++------------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md index a98e2eece7e..8b8159bb008 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md @@ -42,6 +42,24 @@ SIN(<a>) 参数 `<a>` 的正弦值,弧度制表示。 +## 语法 + +```sql +SIN(<x>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 弧度值 | + +## 返回值 + +返回浮点数。特殊情况: + +- 当 x is NULL 时,返回 NULL. + ## 举例 ```sql diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md index e7e7352fb16..126dfa5b7b3 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md @@ -22,28 +22,59 @@ specific language governing permissions and limitations under the License. --> -## positive - ## 描述 + +返回数值本身。 + ## 语法 ```sql -BIGINT positive(BIGINT x) -DOUBLE positive(DOUBLE x) -DECIMAL positive(DECIMAL x) +POSITIVE(<x>) ``` -返回`x`. + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要返回的数值 | + +## 返回值 + +返回一个整型或者浮点数。特殊情况: + +- 当x is NULL 时,返回 NULL ## 举例 +```sql +SELECT positive(-10); ``` -mysql> SELECT positive(-10); + +```text +---------------+ | positive(-10) | +---------------+ | -10 | +---------------+ -mysql> SELECT positive(12); +``` + +```sql +SELECT positive(10.111); +``` + +```text ++------------------+ +| positive(10.111) | ++------------------+ +| 10.111 | ++------------------+ +``` + +```sql +SELECT positive(12); +``` + +```text +--------------+ | positive(12) | +--------------+ @@ -51,5 +82,14 @@ mysql> SELECT positive(12); +--------------+ ``` -### keywords - POSITIVE +```sql +SELECT positive(null); +``` + +```text ++----------------+ +| positive(NULL) | ++----------------+ +| NULL | ++----------------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md index 6b63ba92906..96c2012ab1b 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md @@ -22,72 +22,145 @@ specific language governing permissions and limitations under the License. --> -## round_bankers - ## 描述 -## 语法 -`T round_bankers(T x[, d])` -将`x`使用银行家舍入法后,保留d位小数,`d`默认为0。如果`d`为负数,则小数点左边`d`位为0。如果`x`或`d`为null,返回null。 +将`x`使用银行家舍入法后,保留d位小数,`d`默认为0。 + +如果`d`为负数,则小数点左边`d`位为0。 + +如果`x`或`d`为null,返回null。 如果 d 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。 -+ 如果舍入数介于两个数字之间,则该函数使用银行家的舍入 -+ 在其他情况下,该函数将数字四舍五入到最接近的整数。 +根据银行家舍入算法的规则,当需要舍入到指定的小数位时: + +- 如果要舍入的数字是5,且后面没有其他非零数字,则会检查前一位数字: + - 如果前一位数字是偶数,则直接舍去; + - 如果前一位数字是奇数,则向上进一。 + +- 如果要舍入的数字大于5或者其后有非0的数字,则按照传统的四舍五入规则进行:即大于等于5则进位,否则舍去。 + +例如: +- 对于数值2.5,由于5前面的数字2是偶数,因此结果将舍入为2。 + +- 对于数值3.5,由于5前面的数字3是奇数,因此结果将舍入为4。 + +- 对于数值2.51,因为5后面的数字不是0,所以直接进位,结果为3。 + +## 语法 + +```sql +ROUND_BANKERS(<x> [ , <d>]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 需要四舍五入的数值 | +| `<d>` | 可选,四舍五入需要保留的小数位数,默认为0 | + +## 返回值 + +返回一个整型或者浮点数: + +- 默认情况,参数d = 0 , 返回 `x` 根据银行家舍入算法计算过的整数。 + +- d 为 负数 , 返回小数点左边第一位为0的整数。 + +- x 和 d is NULL , 返回NULL。 + +- d 为一个列时 , 且 `x` 为Decimal类型 , 返回相同精度的浮点数。 ## 举例 +```sql +select round_bankers(0.4); ``` -mysql> select round_bankers(0.4); + +```text +--------------------+ | round_bankers(0.4) | +--------------------+ | 0 | +--------------------+ -mysql> select round_bankers(-3.5); +``` + +```sql +select round_bankers(-3.5); +``` + +```text +---------------------+ | round_bankers(-3.5) | +---------------------+ | -4 | +---------------------+ -mysql> select round_bankers(-3.4); +``` + +```sql +select round_bankers(-3.4); +``` + +```text +---------------------+ | round_bankers(-3.4) | +---------------------+ | -3 | +---------------------+ -mysql> select round_bankers(10.755, 2); +``` + +```sql +select round_bankers(10.755, 2); +``` + +```text +--------------------------+ | round_bankers(10.755, 2) | +--------------------------+ | 10.76 | +--------------------------+ -mysql> select round_bankers(1667.2725, 2); -+-----------------------------+ -| round_bankers(1667.2725, 2) | -+-----------------------------+ -| 1667.27 | -+-----------------------------+ -mysql> select round_bankers(1667.2725, -2); +``` + +```sql +select round_bankers(10.745, 2); +``` + +```text ++--------------------------+ +| round_bankers(10.745, 2) | ++--------------------------+ +| 10.74 | ++--------------------------+ +``` + +```sql +select round_bankers(1667.2725, -2); +``` + +```text +------------------------------+ | round_bankers(1667.2725, -2) | +------------------------------+ | 1700 | +------------------------------+ -mysql> SELECT number - -> , round_bankers(number * 2.5, number - 1) AS rb_decimal_column - -> , round_bankers(number * 2.5, 0) AS rb_decimal_literal - -> , round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column - -> , round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; +``` + +```sql +SELECT number +, round_bankers(number * 2.5, number - 1) AS rb_decimal_column +, round_bankers(number * 2.5, 0) AS rb_decimal_literal +, round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column +, round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal +FROM test_enhanced_round +WHERE rid = 1; +``` + +```text +--------+-------------------+--------------------+------------------+-------------------+ | number | rb_decimal_column | rb_decimal_literal | rb_double_column | rb_double_literal | +--------+-------------------+--------------------+------------------+-------------------+ | 1 | 2.0 | 2 | 2 | 2 | +--------+-------------------+--------------------+------------------+-------------------+ ``` - -### keywords - round_bankers diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md index 3b1853255d6..3737123a427 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md @@ -51,6 +51,7 @@ ROUND(<x> [ , <d> ]) ```sql select round(2.4); ``` + ```text +------------+ | round(2.4) | @@ -62,6 +63,7 @@ select round(2.4); ```sql select round(2.5); ``` + ```text +------------+ | round(2.5) | @@ -73,6 +75,7 @@ select round(2.5); ```sql select round(-3.4); ``` + ```text +-------------+ | round(-3.4) | @@ -84,6 +87,7 @@ select round(-3.4); ```sql select round(-3.5); ``` + ```text +-------------+ | round(-3.5) | @@ -95,6 +99,7 @@ select round(-3.5); ```sql select round(1667.2725, 2); ``` + ```text +---------------------+ | round(1667.2725, 2) | @@ -106,6 +111,7 @@ select round(1667.2725, 2); ```sql select round(1667.2725, -2); ``` + ```text +----------------------+ | round(1667.2725, -2) | @@ -141,4 +147,4 @@ SELECT number, dec90, round(dec90, number), dec91, round(dec91, number), dec99, ``` ## 注意事项 -2.5 会舍入到 3,如果想要舍入到 2 的算法,请使用 `round_bankers` 函数。 \ No newline at end of file +2.5 会舍入到 3,如果想要舍入到 2 的算法,请使用 `round_bankers` 函数。 diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md index 251f5060c03..089f3ce8c51 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md @@ -22,36 +22,80 @@ specific language governing permissions and limitations under the License. --> -## sign - ## 描述 + +返回`x`的符号。负数,零或正数分别对应-1,0或1。 + ## 语法 -`TINYINT sign(DOUBLE x)` -返回`x`的符号.负数,零或正数分别对应-1,0或1. +```sql +SIGN(x) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 自变量 | + +## 返回值 + +返回一个整型: + +- 当 x > 0 时,返回 1,代表整数。 + +- 当 x = 0 时,返回 0,代表零。 + +- 当 x < 0 时,返回 -1,代表负数。 + +- 当 x is NULL时,返回 NULL。 ## 举例 +```sql +select sign(3); ``` -mysql> select sign(3); -+-----------+ -| sign(3.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select sign(0); -+-----------+ -| sign(0.0) | -+-----------+ -| 0 | -mysql> select sign(-10.0); -+-------------+ -| sign(-10.0) | -+-------------+ -| -1 | -+-------------+ -1 row in set (0.01 sec) -``` - -### keywords - SIGN + +```text ++-------------------------+ +| sign(cast(3 as DOUBLE)) | ++-------------------------+ +| 1 | ++-------------------------+ +``` + +```sql +select sign(0); +``` + +```text ++-------------------------+ +| sign(cast(0 as DOUBLE)) | ++-------------------------+ +| 0 | ++-------------------------+ +``` + +```sql +select sign(-10.0); +``` + +```text ++-----------------------------+ +| sign(cast(-10.0 as DOUBLE)) | ++-----------------------------+ +| -1 | ++-----------------------------+ +``` + +```sql +select sign(null); +``` + +```text ++------------+ +| sign(NULL) | ++------------+ +| NULL | ++------------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md index a98e2eece7e..8b8159bb008 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sin.md @@ -42,6 +42,24 @@ SIN(<a>) 参数 `<a>` 的正弦值,弧度制表示。 +## 语法 + +```sql +SIN(<x>) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<x>` | 弧度值 | + +## 返回值 + +返回浮点数。特殊情况: + +- 当 x is NULL 时,返回 NULL. + ## 举例 ```sql diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md index 952e1a9101f..1422e235a31 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md @@ -22,28 +22,59 @@ specific language governing permissions and limitations under the License. --> -## positive +## Description -### description -#### Syntax +Returns the value itself. + +## Syntax ```sql -BIGINT positive(BIGINT x) -DOUBLE positive(DOUBLE x) -DECIMAL positive(DECIMAL x) +POSITIVE(<x>) ``` -Return `x`. -### example +## Parameters + +| Parameter | Description | +|-----------|------------| +| `<x>` | The value that needs to be returned. | + +## Return value + +Returns an integer or a floating-point number. Special cases: + +- If the parameter is NULL, return NULL. + +## Example +```sql +SELECT positive(-10); ``` -mysql> SELECT positive(-10); + +```text +---------------+ | positive(-10) | +---------------+ | -10 | +---------------+ -mysql> SELECT positive(12); +``` + +```sql +SELECT positive(10.111); +``` + +```text ++------------------+ +| positive(10.111) | ++------------------+ +| 10.111 | ++------------------+ +``` + +```sql +SELECT positive(12); +``` + +```text +--------------+ | positive(12) | +--------------+ @@ -51,5 +82,14 @@ mysql> SELECT positive(12); +--------------+ ``` -### keywords - POSITIVE +```sql +SELECT positive(null); +``` + +```text ++----------------+ +| positive(NULL) | ++----------------+ +| NULL | ++----------------+ +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md index 454cf67bb02..ae7c0d52b94 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md @@ -22,73 +22,145 @@ specific language governing permissions and limitations under the License. --> -## round_bankers +## Description -### description -#### Syntax +Round x using the banker's rounding method and keep d decimal places. The default value of d is 0. -`T round_bankers(T x[, d])` -Rounds the argument `x` to `d` specified decimal places. `d` defaults to 0 if not specified. If d is negative, the left d digits of the decimal point are 0. If x or d is null, null is returned. +If d is negative, the |d| digits to the left of the decimal point will be set to 0. -If `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +If x or d is null, return null. -+ If the rounding number is halfway between two numbers, the function uses banker’s rounding. -+ In other cases, the function rounds numbers to the nearest integer. +If d represents a column and the first parameter is of the Decimal type, then the resulting Decimal will have the same number of decimal places as the input Decimal. +According to the rules of the banker's rounding algorithm, when rounding to a specified decimal place: +- If the digit to be rounded is 5 and there are no other non - zero digits following it, the digit immediately preceding it will be checked: + - If the preceding digit is even, the 5 will be simply dropped. + - If the preceding digit is odd, the number will be rounded up. -### example +- If the digit to be rounded is greater than 5 or there are non - zero digits following it, the traditional rounding rules will apply: round up if the digit is greater than or equal to 5, otherwise round down. +For example: + +- For the value 2.5, since the digit 2 before 5 is even, the result will be rounded to 2. + +- For the value 3.5, since the digit 3 before 5 is odd, the result will be rounded to 4. + +- For the value 2.51, since the digit after 5 is not 0, it will be rounded up directly, and the result is 3. + +## Syntax + +```sql +ROUND_BANKERS(<x> [ , <d>]) ``` -mysql> select round_bankers(0.4); + +## Parameters + +| Parameter | Description | +|-----------|------------| +| `<x>` | The number to be rounded | +| `<d>` | Optional, the number of decimal places to round to, with a default value of 0. | + +## Return value + +Returns an integer or a float-point number: + +- By default, when the parameter d = 0, it returns an integer obtained by calculating x using the banker's rounding algorithm. + +- If d is negative, it returns an integer with the first digit to the left of the decimal point being 0. + +- If both x and d are NULL, it returns NULL. + +- If d represents a column and x is of the Decimal type, it returns a floating-point number with the same precision. + +## Example + +```sql +select round_bankers(0.4); +``` + +```text +--------------------+ | round_bankers(0.4) | +--------------------+ | 0 | +--------------------+ -mysql> select round_bankers(-3.5); +``` + +```sql +select round_bankers(-3.5); +``` + +```text +---------------------+ | round_bankers(-3.5) | +---------------------+ | -4 | +---------------------+ -mysql> select round_bankers(-3.4); +``` + +```sql +select round_bankers(-3.4); +``` + +```text +---------------------+ | round_bankers(-3.4) | +---------------------+ | -3 | +---------------------+ -mysql> select round_bankers(10.755, 2); +``` + +```sql +select round_bankers(10.755, 2); +``` + +```text +--------------------------+ | round_bankers(10.755, 2) | +--------------------------+ | 10.76 | +--------------------------+ -mysql> select round_bankers(1667.2725, 2); -+-----------------------------+ -| round_bankers(1667.2725, 2) | -+-----------------------------+ -| 1667.27 | -+-----------------------------+ -mysql> select round_bankers(1667.2725, -2); +``` + +```sql +select round_bankers(10.745, 2); +``` + +```text ++--------------------------+ +| round_bankers(10.745, 2) | ++--------------------------+ +| 10.74 | ++--------------------------+ +``` + +```sql +select round_bankers(1667.2725, -2); +``` + +```text +------------------------------+ | round_bankers(1667.2725, -2) | +------------------------------+ | 1700 | +------------------------------+ -mysql> SELECT number - -> , round_bankers(number * 2.5, number - 1) AS rb_decimal_column - -> , round_bankers(number * 2.5, 0) AS rb_decimal_literal - -> , round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column - -> , round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; +``` + +```sql +SELECT number +, round_bankers(number * 2.5, number - 1) AS rb_decimal_column +, round_bankers(number * 2.5, 0) AS rb_decimal_literal +, round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column +, round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal +FROM test_enhanced_round +WHERE rid = 1; +``` + +```text +--------+-------------------+--------------------+------------------+-------------------+ | number | rb_decimal_column | rb_decimal_literal | rb_double_column | rb_double_literal | +--------+-------------------+--------------------+------------------+-------------------+ | 1 | 2.0 | 2 | 2 | 2 | +--------+-------------------+--------------------+------------------+-------------------+ -``` - -### keywords - round_bankers +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md index 53840b55c51..00851fab629 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md @@ -53,6 +53,7 @@ ROUND(<x> [ , <d> ]) ```sql select round(2.4); ``` + ```text +------------+ | round(2.4) | @@ -64,6 +65,7 @@ select round(2.4); ```sql select round(2.5); ``` + ```text +------------+ | round(2.5) | @@ -75,6 +77,7 @@ select round(2.5); ```sql select round(-3.4); ``` + ```text +-------------+ | round(-3.4) | @@ -86,6 +89,7 @@ select round(-3.4); ```sql select round(-3.5); ``` + ```text +-------------+ | round(-3.5) | @@ -97,6 +101,7 @@ select round(-3.5); ```sql select round(1667.2725, 2); ``` + ```text +---------------------+ | round(1667.2725, 2) | @@ -108,6 +113,7 @@ select round(1667.2725, 2); ```sql select round(1667.2725, -2); ``` + ```text +----------------------+ | round(1667.2725, -2) | @@ -143,4 +149,4 @@ SELECT number, dec90, round(dec90, number), dec91, round(dec91, number), dec99, ``` ## Usage Note -2.5 will round to 3. If you want to round to 2, use the `round_bankers` function. \ No newline at end of file +2.5 will round to 3. If you want to round to 2, use the `round_bankers` function. diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md index 4f98136466e..90bbee6ca7e 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md @@ -22,36 +22,80 @@ specific language governing permissions and limitations under the License. --> -## sign +## Description -### description -#### Syntax - -`TINYINT sign(DOUBLE x)` Returns the sign of `x`. Negative, zero or positive numbers correspond to -1, 0 or 1 respectively. -### example - -``` -mysql> select sign(3); -+-----------+ -| sign(3.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select sign(0); -+-----------+ -| sign(0.0) | -+-----------+ -| 0 | -mysql> select sign(-10.0); -+-------------+ -| sign(-10.0) | -+-------------+ -| -1 | -+-------------+ -1 row in set (0.01 sec) -``` - -### keywords - SIGN +## Syntax + +```sql +SIGN(x) +``` + +## Parameters + +| Parameter | Description | +|-----------|------------| +| `<x>` | independent variable | + +## Return value + +Returns an integer: + +- If x > 0, it returns 1, representing a positive number. + +- If x = 0, it returns 0, representing zero. + +- If x < 0, it returns -1, representing a negative number. + +- If x is NULL, it returns NULL. + +## Example + +```sql +select sign(3); +``` + +```text ++-------------------------+ +| sign(cast(3 as DOUBLE)) | ++-------------------------+ +| 1 | ++-------------------------+ +``` + +```sql +select sign(0); +``` + +```text ++-------------------------+ +| sign(cast(0 as DOUBLE)) | ++-------------------------+ +| 0 | ++-------------------------+ +``` + +```sql +select sign(-10.0); +``` + +```text ++-----------------------------+ +| sign(cast(-10.0 as DOUBLE)) | ++-----------------------------+ +| -1 | ++-----------------------------+ +``` + +```sql +select sign(null); +``` + +```text ++------------+ +| sign(NULL) | ++------------+ +| NULL | ++------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md index 952e1a9101f..1422e235a31 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/positive.md @@ -22,28 +22,59 @@ specific language governing permissions and limitations under the License. --> -## positive +## Description -### description -#### Syntax +Returns the value itself. + +## Syntax ```sql -BIGINT positive(BIGINT x) -DOUBLE positive(DOUBLE x) -DECIMAL positive(DECIMAL x) +POSITIVE(<x>) ``` -Return `x`. -### example +## Parameters + +| Parameter | Description | +|-----------|------------| +| `<x>` | The value that needs to be returned. | + +## Return value + +Returns an integer or a floating-point number. Special cases: + +- If the parameter is NULL, return NULL. + +## Example +```sql +SELECT positive(-10); ``` -mysql> SELECT positive(-10); + +```text +---------------+ | positive(-10) | +---------------+ | -10 | +---------------+ -mysql> SELECT positive(12); +``` + +```sql +SELECT positive(10.111); +``` + +```text ++------------------+ +| positive(10.111) | ++------------------+ +| 10.111 | ++------------------+ +``` + +```sql +SELECT positive(12); +``` + +```text +--------------+ | positive(12) | +--------------+ @@ -51,5 +82,14 @@ mysql> SELECT positive(12); +--------------+ ``` -### keywords - POSITIVE +```sql +SELECT positive(null); +``` + +```text ++----------------+ +| positive(NULL) | ++----------------+ +| NULL | ++----------------+ +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md index 454cf67bb02..ae7c0d52b94 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round-bankers.md @@ -22,73 +22,145 @@ specific language governing permissions and limitations under the License. --> -## round_bankers +## Description -### description -#### Syntax +Round x using the banker's rounding method and keep d decimal places. The default value of d is 0. -`T round_bankers(T x[, d])` -Rounds the argument `x` to `d` specified decimal places. `d` defaults to 0 if not specified. If d is negative, the left d digits of the decimal point are 0. If x or d is null, null is returned. +If d is negative, the |d| digits to the left of the decimal point will be set to 0. -If `d` is a column, and `x` has Decimal type, scale of result Decimal will always be same with input Decimal. +If x or d is null, return null. -+ If the rounding number is halfway between two numbers, the function uses banker’s rounding. -+ In other cases, the function rounds numbers to the nearest integer. +If d represents a column and the first parameter is of the Decimal type, then the resulting Decimal will have the same number of decimal places as the input Decimal. +According to the rules of the banker's rounding algorithm, when rounding to a specified decimal place: +- If the digit to be rounded is 5 and there are no other non - zero digits following it, the digit immediately preceding it will be checked: + - If the preceding digit is even, the 5 will be simply dropped. + - If the preceding digit is odd, the number will be rounded up. -### example +- If the digit to be rounded is greater than 5 or there are non - zero digits following it, the traditional rounding rules will apply: round up if the digit is greater than or equal to 5, otherwise round down. +For example: + +- For the value 2.5, since the digit 2 before 5 is even, the result will be rounded to 2. + +- For the value 3.5, since the digit 3 before 5 is odd, the result will be rounded to 4. + +- For the value 2.51, since the digit after 5 is not 0, it will be rounded up directly, and the result is 3. + +## Syntax + +```sql +ROUND_BANKERS(<x> [ , <d>]) ``` -mysql> select round_bankers(0.4); + +## Parameters + +| Parameter | Description | +|-----------|------------| +| `<x>` | The number to be rounded | +| `<d>` | Optional, the number of decimal places to round to, with a default value of 0. | + +## Return value + +Returns an integer or a float-point number: + +- By default, when the parameter d = 0, it returns an integer obtained by calculating x using the banker's rounding algorithm. + +- If d is negative, it returns an integer with the first digit to the left of the decimal point being 0. + +- If both x and d are NULL, it returns NULL. + +- If d represents a column and x is of the Decimal type, it returns a floating-point number with the same precision. + +## Example + +```sql +select round_bankers(0.4); +``` + +```text +--------------------+ | round_bankers(0.4) | +--------------------+ | 0 | +--------------------+ -mysql> select round_bankers(-3.5); +``` + +```sql +select round_bankers(-3.5); +``` + +```text +---------------------+ | round_bankers(-3.5) | +---------------------+ | -4 | +---------------------+ -mysql> select round_bankers(-3.4); +``` + +```sql +select round_bankers(-3.4); +``` + +```text +---------------------+ | round_bankers(-3.4) | +---------------------+ | -3 | +---------------------+ -mysql> select round_bankers(10.755, 2); +``` + +```sql +select round_bankers(10.755, 2); +``` + +```text +--------------------------+ | round_bankers(10.755, 2) | +--------------------------+ | 10.76 | +--------------------------+ -mysql> select round_bankers(1667.2725, 2); -+-----------------------------+ -| round_bankers(1667.2725, 2) | -+-----------------------------+ -| 1667.27 | -+-----------------------------+ -mysql> select round_bankers(1667.2725, -2); +``` + +```sql +select round_bankers(10.745, 2); +``` + +```text ++--------------------------+ +| round_bankers(10.745, 2) | ++--------------------------+ +| 10.74 | ++--------------------------+ +``` + +```sql +select round_bankers(1667.2725, -2); +``` + +```text +------------------------------+ | round_bankers(1667.2725, -2) | +------------------------------+ | 1700 | +------------------------------+ -mysql> SELECT number - -> , round_bankers(number * 2.5, number - 1) AS rb_decimal_column - -> , round_bankers(number * 2.5, 0) AS rb_decimal_literal - -> , round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column - -> , round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal - -> FROM test_enhanced_round - -> WHERE rid = 1; +``` + +```sql +SELECT number +, round_bankers(number * 2.5, number - 1) AS rb_decimal_column +, round_bankers(number * 2.5, 0) AS rb_decimal_literal +, round_bankers(cast(number * 2.5 AS DOUBLE), number - 1) AS rb_double_column +, round_bankers(cast(number * 2.5 AS DOUBLE), 0) AS rb_double_literal +FROM test_enhanced_round +WHERE rid = 1; +``` + +```text +--------+-------------------+--------------------+------------------+-------------------+ | number | rb_decimal_column | rb_decimal_literal | rb_double_column | rb_double_literal | +--------+-------------------+--------------------+------------------+-------------------+ | 1 | 2.0 | 2 | 2 | 2 | +--------+-------------------+--------------------+------------------+-------------------+ -``` - -### keywords - round_bankers +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md index 53840b55c51..00851fab629 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/round.md @@ -53,6 +53,7 @@ ROUND(<x> [ , <d> ]) ```sql select round(2.4); ``` + ```text +------------+ | round(2.4) | @@ -64,6 +65,7 @@ select round(2.4); ```sql select round(2.5); ``` + ```text +------------+ | round(2.5) | @@ -75,6 +77,7 @@ select round(2.5); ```sql select round(-3.4); ``` + ```text +-------------+ | round(-3.4) | @@ -86,6 +89,7 @@ select round(-3.4); ```sql select round(-3.5); ``` + ```text +-------------+ | round(-3.5) | @@ -97,6 +101,7 @@ select round(-3.5); ```sql select round(1667.2725, 2); ``` + ```text +---------------------+ | round(1667.2725, 2) | @@ -108,6 +113,7 @@ select round(1667.2725, 2); ```sql select round(1667.2725, -2); ``` + ```text +----------------------+ | round(1667.2725, -2) | @@ -143,4 +149,4 @@ SELECT number, dec90, round(dec90, number), dec91, round(dec91, number), dec99, ``` ## Usage Note -2.5 will round to 3. If you want to round to 2, use the `round_bankers` function. \ No newline at end of file +2.5 will round to 3. If you want to round to 2, use the `round_bankers` function. diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md index 4f98136466e..90bbee6ca7e 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/numeric-functions/sign.md @@ -22,36 +22,80 @@ specific language governing permissions and limitations under the License. --> -## sign +## Description -### description -#### Syntax - -`TINYINT sign(DOUBLE x)` Returns the sign of `x`. Negative, zero or positive numbers correspond to -1, 0 or 1 respectively. -### example - -``` -mysql> select sign(3); -+-----------+ -| sign(3.0) | -+-----------+ -| 1 | -+-----------+ -mysql> select sign(0); -+-----------+ -| sign(0.0) | -+-----------+ -| 0 | -mysql> select sign(-10.0); -+-------------+ -| sign(-10.0) | -+-------------+ -| -1 | -+-------------+ -1 row in set (0.01 sec) -``` - -### keywords - SIGN +## Syntax + +```sql +SIGN(x) +``` + +## Parameters + +| Parameter | Description | +|-----------|------------| +| `<x>` | independent variable | + +## Return value + +Returns an integer: + +- If x > 0, it returns 1, representing a positive number. + +- If x = 0, it returns 0, representing zero. + +- If x < 0, it returns -1, representing a negative number. + +- If x is NULL, it returns NULL. + +## Example + +```sql +select sign(3); +``` + +```text ++-------------------------+ +| sign(cast(3 as DOUBLE)) | ++-------------------------+ +| 1 | ++-------------------------+ +``` + +```sql +select sign(0); +``` + +```text ++-------------------------+ +| sign(cast(0 as DOUBLE)) | ++-------------------------+ +| 0 | ++-------------------------+ +``` + +```sql +select sign(-10.0); +``` + +```text ++-----------------------------+ +| sign(cast(-10.0 as DOUBLE)) | ++-----------------------------+ +| -1 | ++-----------------------------+ +``` + +```sql +select sign(null); +``` + +```text ++------------+ +| sign(NULL) | ++------------+ +| NULL | ++------------+ +``` --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org