diff --git a/docs/en/query_language/select.md b/docs/en/query_language/select.md index 76c25337b9cc073c81fddd0ac73a023f9b0cc67a..1ec4abd24e51c730561ebe5817c1d84e4c2a8f2c 100644 --- a/docs/en/query_language/select.md +++ b/docs/en/query_language/select.md @@ -564,29 +564,29 @@ ClickHouse doesn't directly support syntax with commas, so we don't recommend us Tables for `ASOF JOIN` must have an ordered sequence column. This column cannot be alone in a table, and should be one of the data types: `UInt32`, `UInt64`, `Float32`, `Float64`, `Date`, and `DateTime`. -You can use the following types of syntax: +Syntax `ASOF JOIN ... ON`: -- `ASOF JOIN ... ON` +```sql +SELECT expressions_list +FROM table_1 +ASOF LEFT JOIN table_2 +ON equi_cond AND closest_match_cond +``` - ```sql - SELECT expressions_list - FROM table_1 - ASOF LEFT JOIN table_2 - ON equi_cond AND closest_match_cond - ``` +You can use any number of equality conditions and exactly one closest match condition. For example, `SELECT count() FROM table_1 ASOF LEFT JOIN table_2 ON table_1.a == table_2.b AND table_2.t <= table_1.t`. - You can use any number of equality conditions and exactly one closest match condition. For example, `SELECT count() FROM A ASOF LEFT JOIN B ON A.a == B.b AND B.t <= A.t`. Only `table_2.some_col <= table_1.some_col` and `table_1.some_col >= table2.some_col` condition types are available. You can't apply other conditions like `>` or `!=`. +Conditions supported for the closest match: `>`, `>=`, `<`, `<=`. -- `ASOF JOIN ... USING` +Syntax `ASOF JOIN ... USING`: - ```sql - SELECT expressions_list - FROM table_1 - ASOF JOIN table_2 - USING (equi_column1, ... equi_columnN, asof_column) - ``` +```sql +SELECT expressions_list +FROM table_1 +ASOF JOIN table_2 +USING (equi_column1, ... equi_columnN, asof_column) +``` - `ASOF JOIN` uses `equi_columnX` for joining on equality and `asof_column` for joining on the closest match with the `table_1.asof_column >= table2.asof_column` condition. The `asof_column` column must be the last in the `USING` clause. +`ASOF JOIN` uses `equi_columnX` for joining on equality and `asof_column` for joining on the closest match with the `table_1.asof_column >= table_2.asof_column` condition. The `asof_column` column always the last one in the `USING` clause. For example, consider the following tables: @@ -602,7 +602,7 @@ event_1_2 | 13:00 | 42 event_2_3 | 13:00 | 42 ... ... ``` -`ASOF JOIN` can take the timestamp of a user event from `table_1` and find an event in `table_2` where the timestamp is closest (equal to or less) to the timestamp of the event from `table_1`. Here, the `user_id` column can be used for joining on equality and the `ev_time` column can be used for joining on the closest match. In our example, `event_1_1` can be joined with `event_2_1` and `event_1_2` can be joined with `event_2_3`, but `event_2_2` can't be joined. +`ASOF JOIN` can take the timestamp of a user event from `table_1` and find an event in `table_2` where the timestamp is closest to the timestamp of the event from `table_1` corresponding to the closest match condition. Equal timestamp values are the closest if available. Here, the `user_id` column can be used for joining on equality and the `ev_time` column can be used for joining on the closest match. In our example, `event_1_1` can be joined with `event_2_1` and `event_1_2` can be joined with `event_2_3`, but `event_2_2` can't be joined. !!! note "Note" diff --git a/docs/ru/query_language/select.md b/docs/ru/query_language/select.md index e35f0c508978820911c9fd264353489966f2a8c1..e62269be52c3feb77848008f82f4285e1f33dd27 100644 --- a/docs/ru/query_language/select.md +++ b/docs/ru/query_language/select.md @@ -572,29 +572,29 @@ ClickHouse не поддерживает синтаксис с запятыми Таблицы для `ASOF JOIN` должны иметь столбец с отсортированной последовательностью. Этот столбец не может быть единственным в таблице и должен быть одного из типов: `UInt32`, `UInt64`, `Float32`, `Float64`, `Date` и `DateTime`. -Можно использовать следующие типы синтаксиса: +Синтаксис `ASOF JOIN ... ON`: -- `ASOF JOIN ... ON` +```sql +SELECT expressions_list +FROM table_1 +ASOF LEFT JOIN table_2 +ON equi_cond AND closest_match_cond +``` - ```sql - SELECT expressions_list - FROM table_1 - ASOF LEFT JOIN table_2 - ON equi_cond AND closest_match_cond - ``` +Можно использовать произвольное количество условий равенства и одно условие на ближайшее совпадение. Например, `SELECT count() FROM table_1 ASOF LEFT JOIN table_2 ON table_1.a == table_2.b AND table_2.t <= table_1.t`. - Можно использовать произвольное количество условий равенства и одно условие на ближайшее совпадение. Например, `SELECT count() FROM A ASOF LEFT JOIN B ON A.a == B.b AND B.t <= A.t`. Можно использовать только условия `table_2.some_col <= table_1.some_col` и `table_1.some_col >= table2.some_col`. Условия типа `>` или `!=` не поддерживаются. +Условия, поддержанные для проверки на ближайшее совпадение: `>`, `>=`, `<`, `<=`. -- `ASOF JOIN ... USING` +Синтаксис `ASOF JOIN ... USING`: - ```sql - SELECT expressions_list - FROM table_1 - ASOF JOIN table_2 - USING (equi_column1, ... equi_columnN, asof_column) - ``` +```sql +SELECT expressions_list +FROM table_1 +ASOF JOIN table_2 +USING (equi_column1, ... equi_columnN, asof_column) +``` - Для слияния по равенству `ASOF JOIN` использует `equi_columnX`, а для слияния по ближайшему совпадению использует `asof_column` с условием `table_1.asof_column >= table2.asof_column`. Столбец `asof_column` должен быть последним в секции `USING`. +Для слияния по равенству `ASOF JOIN` использует `equi_columnX`, а для слияния по ближайшему совпадению использует `asof_column` с условием `table_1.asof_column >= table_2.asof_column`. Столбец `asof_column` должен быть последним в секции `USING`. Например, рассмотрим следующие таблицы: @@ -609,7 +609,7 @@ event_1_2 | 13:00 | 42 event_2_3 | 13:00 | 42 ... ... ``` -`ASOF JOIN` принимает метку времени пользовательского события из `table_1` и находит такое событие в `table_2` метка времени которого наиболее близка (равна или меньше) к метке времени события из `table_1`. При этом столбец `user_id` используется для объединения по равенству, а столбец `ev_time` для объединения по ближайшему совпадению. В нашем примере `event_1_1` может быть объединено с `event_2_1`, `event_1_2` может быть объединено с `event_2_3`, а `event_2_2` не объединяется. +`ASOF JOIN` принимает метку времени пользовательского события из `table_1` и находит такое событие в `table_2` метка времени которого наиболее близка к метке времени события из `table_1` в соответствии с условием на ближайшее совпадение. При этом столбец `user_id` используется для объединения по равенству, а столбец `ev_time` для объединения по ближайшему совпадению. В нашем примере `event_1_1` может быть объединено с `event_2_1`, `event_1_2` может быть объединено с `event_2_3`, а `event_2_2` не объединяется. !!! note "Примечание" `ASOF JOIN` не поддержан для движка таблиц [Join](../operations/table_engines/join.md).