Help wanted!
The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable. You can also use the original English version as a reference.
Null許容集計を操作するための関数
isNull
引数が NULL.
isNull(x)
パラメータ
x
— A value with a non-compound data type.
戻り値
1
もしx
はNULL
.0
もしx
ではないNULL
.
例
入力テーブル
┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │ 3 │
└───┴──────┘
クエリ
SELECT x FROM t_null WHERE isNull(y)
┌─x─┐
│ 1 │
└───┘
isNotNull
引数が NULL.
isNotNull(x)
パラメータ:
x
— A value with a non-compound data type.
戻り値
0
もしx
はNULL
.1
もしx
ではないNULL
.
例
入力テーブル
┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │ 3 │
└───┴──────┘
クエリ
SELECT x FROM t_null WHERE isNotNull(y)
┌─x─┐
│ 2 │
└───┘
合体
左から右にチェックするかどうか NULL
引数が渡され、最初のnonを返します-NULL
引数。
coalesce(x,...)
パラメータ:
- 非複合型の任意の数のパラメーター。 すべてのパラメータに対応していることが必要となるデータ型になります。
戻り値
- 最初の非-
NULL
引数。 NULL
すべての引数がNULL
.
例
顧客に連絡する複数の方法を指定できる連絡先のリストを検討してください。
┌─name─────┬─mail─┬─phone─────┬──icq─┐
│ client 1 │ ᴺᵁᴸᴸ │ 123-45-67 │ 123 │
│ client 2 │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │
└──────────┴──────┴───────────┴──────┘
その mail
と phone
フィールドはString型ですが、 icq
フィールドは UInt32
したがって、変換する必要があります String
.
連絡先リストから顧客に対して最初に使用可能な連絡先方法を取得する:
SELECT coalesce(mail, phone, CAST(icq,'Nullable(String)')) FROM aBook
┌─name─────┬─coalesce(mail, phone, CAST(icq, 'Nullable(String)'))─┐
│ client 1 │ 123-45-67 │
│ client 2 │ ᴺᵁᴸᴸ │
└──────────┴──────────────────────────────────────────────────────┘
ifNull
Main引数が次の場合、代替値を返します NULL
.
ifNull(x,alt)
パラメータ:
x
— The value to check forNULL
.alt
— The value that the function returns ifx
はNULL
.
戻り値
- 値
x
,ifx
ではないNULL
. - 値
alt
,ifx
はNULL
.
例
SELECT ifNull('a', 'b')
┌─ifNull('a', 'b')─┐
│ a │
└──────────────────┘
SELECT ifNull(NULL, 'b')
┌─ifNull(NULL, 'b')─┐
│ b │
└───────────────────┘
ヌリフ
ツづゥツ。 NULL
引数が等しい場合。
nullIf(x, y)
パラメータ:
x
, y
— Values for comparison. They must be compatible types, or ClickHouse will generate an exception.
戻り値
NULL
、引数が等しい場合。- その
x
引数が等しくない場合の値。
例
SELECT nullIf(1, 1)
┌─nullIf(1, 1)─┐
│ ᴺᵁᴸᴸ │
└──────────────┘
SELECT nullIf(1, 2)
┌─nullIf(1, 2)─┐
│ 1 │
└──────────────┘
assumeNotNull
結果はtypeの値になります Null可能 非のため- Nullable
値が NULL
.
assumeNotNull(x)
パラメータ:
x
— The original value.
戻り値
- 非からの元の値-
Nullable
そうでない場合は、タイプNULL
. - 非のデフォルト値-
Nullable
元の値がNULL
.
例
を考える t_null
テーブル。
SHOW CREATE TABLE t_null
┌─statement─────────────────────────────────────────────────────────────────┐
│ CREATE TABLE default.t_null ( x Int8, y Nullable(Int8)) ENGINE = TinyLog │
└───────────────────────────────────────────────────────────────────────────┘
┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │ 3 │
└───┴──────┘
を適用する assumeNotNull
に対する関数 y
列。
SELECT assumeNotNull(y) FROM t_null
┌─assumeNotNull(y)─┐
│ 0 │
│ 3 │
└──────────────────┘
SELECT toTypeName(assumeNotNull(y)) FROM t_null
┌─toTypeName(assumeNotNull(y))─┐
│ Int8 │
│ Int8 │
└──────────────────────────────┘
toNullable
引数の型を次のように変換します Nullable
.
toNullable(x)
パラメータ:
x
— The value of any non-compound type.
戻り値
- Aを持つ入力値
Nullable
タイプ。
例
SELECT toTypeName(10)
┌─toTypeName(10)─┐
│ UInt8 │
└────────────────┘
SELECT toTypeName(toNullable(10))
┌─toTypeName(toNullable(10))─┐
│ Nullable(UInt8) │
└────────────────────────────┘