Nikita Fomichev 2024-04-02 18:33:56 +02:00
parent 18402c6191
commit 478cabee22
2 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1 @@
123456789 111 222

View File

@ -0,0 +1,14 @@
CREATE TABLE IF NOT EXISTS first engine = MergeTree PARTITION BY (inn, toYYYYMM(received)) ORDER BY (inn, sessionId)
AS SELECT now() AS received, '123456789' AS inn, '42' AS sessionId;
CREATE TABLE IF NOT EXISTS second engine = MergeTree PARTITION BY (inn, toYYYYMM(received)) ORDER BY (inn, sessionId)
AS SELECT now() AS received, '123456789' AS inn, '42' AS sessionId, '111' AS serial, '222' AS reg;
SELECT alias_first.inn, arrayFirst(t -> isNotNull(t), regInfo.1), arrayFirst(t -> isNotNull(t), regInfo.2)
FROM first AS alias_first
INNER JOIN (
SELECT alias_second.inn, alias_second.sessionId, groupArray((serial, reg)) AS regInfo
FROM second AS alias_second
GROUP BY inn, sessionId
) AS resp ON (alias_first.inn = resp.inn) AND (alias_first.sessionId = resp.sessionId)
WHERE if('123456789' IS NOT NULL, alias_first.inn = '123456789', 1)