ClickHouse/tests/queries/1_stateful/00063_loyalty_joins.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
2.3 KiB
MySQL
Raw Normal View History

2023-02-03 13:34:18 +00:00
-- Tags: no-parallel-replicas
SET any_join_distinct_right_table_keys = 1;
SET joined_subquery_requires_alias = 0;
SELECT
2023-02-03 13:34:18 +00:00
loyalty,
count()
2023-02-03 13:34:18 +00:00
FROM test.hits ANY LEFT JOIN
(
SELECT
2023-02-03 13:34:18 +00:00
UserID,
sum(SearchEngineID = 2) AS yandex,
sum(SearchEngineID = 3) AS google,
toInt8(if(yandex > google, yandex / (yandex + google), -google / (yandex + google)) * 10) AS loyalty
FROM test.hits
WHERE (SearchEngineID = 2) OR (SearchEngineID = 3)
GROUP BY UserID
HAVING (yandex + google) > 10
) USING UserID
GROUP BY loyalty
ORDER BY loyalty ASC;
SELECT
2023-02-03 13:34:18 +00:00
loyalty,
count()
FROM
(
SELECT UserID
FROM test.hits
2023-02-03 13:34:18 +00:00
) ANY LEFT JOIN
(
SELECT
2023-02-03 13:34:18 +00:00
UserID,
sum(SearchEngineID = 2) AS yandex,
sum(SearchEngineID = 3) AS google,
toInt8(if(yandex > google, yandex / (yandex + google), -google / (yandex + google)) * 10) AS loyalty
FROM test.hits
WHERE (SearchEngineID = 2) OR (SearchEngineID = 3)
GROUP BY UserID
HAVING (yandex + google) > 10
) USING UserID
GROUP BY loyalty
ORDER BY loyalty ASC;
SELECT
2023-02-03 13:34:18 +00:00
loyalty,
count()
FROM
(
SELECT
2023-02-03 13:34:18 +00:00
loyalty,
UserID
FROM
(
SELECT UserID
FROM test.hits
2023-02-03 13:34:18 +00:00
) ANY LEFT JOIN
(
SELECT
2023-02-03 13:34:18 +00:00
UserID,
sum(SearchEngineID = 2) AS yandex,
sum(SearchEngineID = 3) AS google,
toInt8(if(yandex > google, yandex / (yandex + google), -google / (yandex + google)) * 10) AS loyalty
FROM test.hits
WHERE (SearchEngineID = 2) OR (SearchEngineID = 3)
GROUP BY UserID
HAVING (yandex + google) > 10
) USING UserID
)
GROUP BY loyalty
ORDER BY loyalty ASC;
SELECT
2023-02-03 13:34:18 +00:00
loyalty,
count() AS c,
bar(log(c + 1) * 1000, 0, log(3000000) * 1000, 80)
2023-02-03 13:34:18 +00:00
FROM test.hits ANY INNER JOIN
(
SELECT
2023-02-03 13:34:18 +00:00
UserID,
toInt8(if(yandex > google, yandex / (yandex + google), -google / (yandex + google)) * 10) AS loyalty
FROM
(
SELECT
2023-02-03 13:34:18 +00:00
UserID,
sum(SearchEngineID = 2) AS yandex,
sum(SearchEngineID = 3) AS google
FROM test.hits
WHERE (SearchEngineID = 2) OR (SearchEngineID = 3)
GROUP BY UserID
HAVING (yandex + google) > 10
)
) USING UserID
GROUP BY loyalty
ORDER BY loyalty ASC;