[docs] add document conditional-functions (#8339)
Add conditional-functions.
This commit is contained in:
@ -0,0 +1,72 @@
|
||||
---
|
||||
{
|
||||
"title": "case",
|
||||
"language": "en"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
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
|
||||
```
|
||||
|
||||
Compare the expression with multiple possible values, and return the corresponding results when matching
|
||||
|
||||
## 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": "en"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
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)`
|
||||
|
||||
|
||||
Returns the first non empty expression in the parameter (from left to right)
|
||||
|
||||
## example
|
||||
|
||||
```
|
||||
mysql> select coalesce(NULL, '1111', '0000');
|
||||
+--------------------------------+
|
||||
| coalesce(NULL, '1111', '0000') |
|
||||
+--------------------------------+
|
||||
| 1111 |
|
||||
+--------------------------------+
|
||||
```
|
||||
## keyword
|
||||
COALESCE
|
||||
@ -0,0 +1,50 @@
|
||||
---
|
||||
{
|
||||
"title": "if",
|
||||
"language": "en"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
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)`
|
||||
|
||||
|
||||
Returns valueTrue when condition is true, returns valueFalseOrNull otherwise.
|
||||
|
||||
The return type is the type of the result of the valueTrue/valueFalseOrNull expression
|
||||
|
||||
## 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": "en"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
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)`
|
||||
|
||||
|
||||
If the value of expr1 is not null, expr1 is returned, otherwise expr2 is returned
|
||||
|
||||
## 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": "en"
|
||||
}
|
||||
---
|
||||
|
||||
<!--
|
||||
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)`
|
||||
|
||||
|
||||
If the two parameters are equal, null is returned. Otherwise, the value of the first parameter is returned. It has the same effect as the following `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
|
||||
Reference in New Issue
Block a user