mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 20:32:43 +00:00
2e1f6bc56d
* replace exit with assert in test_single_page * improve save_raw_single_page docs option * More grammar fixes * "Built from" link in new tab * fix mistype * Example of include in docs * add anchor to meeting form * Draft of translation helper * WIP on translation helper * Replace some fa docs content with machine translation * add normalize-en-markdown.sh * normalize some en markdown * normalize some en markdown * admonition support * normalize * normalize * normalize * support wide tables * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * normalize * lightly edited machine translation of introdpection.md * lightly edited machhine translation of lazy.md * WIP on translation utils * Normalize ru docs * Normalize other languages * some fixes * WIP on normalize/translate tools * add requirements.txt * [experimental] add es docs language as machine translated draft * remove duplicate script * Back to wider tab-stop (narrow renders not so well)
45 lines
1.4 KiB
Markdown
45 lines
1.4 KiB
Markdown
# 条件函数 {#tiao-jian-han-shu}
|
||
|
||
## if(cond, then, else), cond ? operator then : else {#ifcond-then-else-cond-operator-then-else}
|
||
|
||
如果`cond != 0`则返回`then`,如果`cond = 0`则返回`else`。
|
||
`cond`必须是`UInt8`类型,`then`和`else`必须存在最低的共同类型。
|
||
|
||
`then`和`else`可以是`NULL`
|
||
|
||
## multiIf {#multiif}
|
||
|
||
允许您在查询中更紧凑地编写[CASE](../operators.md#operator_case)运算符。
|
||
|
||
multiIf(cond_1, then_1, cond_2, then_2...else)
|
||
|
||
**参数:**
|
||
|
||
- `cond_N` — 函数返回`then_N`的条件。
|
||
- `then_N` — 执行时函数的结果。
|
||
- `else` — 如果没有满足任何条件,则为函数的结果。
|
||
|
||
该函数接受`2N + 1`参数。
|
||
|
||
**返回值**
|
||
|
||
该函数返回值«then\_N»或«else»之一,具体取决于条件`cond_N`。
|
||
|
||
**示例**
|
||
|
||
存在如下一张表
|
||
|
||
┌─x─┬────y─┐
|
||
│ 1 │ ᴺᵁᴸᴸ │
|
||
│ 2 │ 3 │
|
||
└───┴──────┘
|
||
|
||
执行查询 `SELECT multiIf(isNull(y) x, y < 3, y, NULL) FROM t_null`。结果:
|
||
|
||
┌─multiIf(isNull(y), x, less(y, 3), y, NULL)─┐
|
||
│ 1 │
|
||
│ ᴺᵁᴸᴸ │
|
||
└────────────────────────────────────────────┘
|
||
|
||
[来源文章](https://clickhouse.tech/docs/en/query_language/functions/conditional_functions/) <!--hide-->
|