2023-02-03 13:34:18 +00:00
|
|
|
-- Tags: no-parallel-replicas
|
|
|
|
|
2019-08-08 14:20:25 +00:00
|
|
|
SET any_join_distinct_right_table_keys = 1;
|
2019-09-02 12:53:31 +00:00
|
|
|
SET joined_subquery_requires_alias = 0;
|
2019-08-08 14:20:25 +00:00
|
|
|
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2023-02-03 13:34:18 +00:00
|
|
|
loyalty,
|
2018-08-07 17:08:51 +00:00
|
|
|
count()
|
2023-02-03 13:34:18 +00:00
|
|
|
FROM test.hits ANY LEFT JOIN
|
2018-08-07 17:08:51 +00:00
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2023-02-03 13:34:18 +00:00
|
|
|
UserID,
|
|
|
|
sum(SearchEngineID = 2) AS yandex,
|
|
|
|
sum(SearchEngineID = 3) AS google,
|
2018-08-07 17:08:51 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2023-02-03 13:34:18 +00:00
|
|
|
loyalty,
|
2018-08-07 17:08:51 +00:00
|
|
|
count()
|
2021-05-15 09:11:13 +00:00
|
|
|
FROM
|
2018-08-07 17:08:51 +00:00
|
|
|
(
|
|
|
|
SELECT UserID
|
|
|
|
FROM test.hits
|
2023-02-03 13:34:18 +00:00
|
|
|
) ANY LEFT JOIN
|
2018-08-07 17:08:51 +00:00
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2023-02-03 13:34:18 +00:00
|
|
|
UserID,
|
|
|
|
sum(SearchEngineID = 2) AS yandex,
|
|
|
|
sum(SearchEngineID = 3) AS google,
|
2018-08-07 17:08:51 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2023-02-03 13:34:18 +00:00
|
|
|
loyalty,
|
2018-08-07 17:08:51 +00:00
|
|
|
count()
|
2021-05-15 09:11:13 +00:00
|
|
|
FROM
|
2018-08-07 17:08:51 +00:00
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2023-02-03 13:34:18 +00:00
|
|
|
loyalty,
|
2018-08-07 17:08:51 +00:00
|
|
|
UserID
|
2021-05-15 09:11:13 +00:00
|
|
|
FROM
|
2018-08-07 17:08:51 +00:00
|
|
|
(
|
|
|
|
SELECT UserID
|
|
|
|
FROM test.hits
|
2023-02-03 13:34:18 +00:00
|
|
|
) ANY LEFT JOIN
|
2018-08-07 17:08:51 +00:00
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2023-02-03 13:34:18 +00:00
|
|
|
UserID,
|
|
|
|
sum(SearchEngineID = 2) AS yandex,
|
|
|
|
sum(SearchEngineID = 3) AS google,
|
2018-08-07 17:08:51 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2023-02-03 13:34:18 +00:00
|
|
|
loyalty,
|
|
|
|
count() AS c,
|
2018-08-07 17:08:51 +00:00
|
|
|
bar(log(c + 1) * 1000, 0, log(3000000) * 1000, 80)
|
2023-02-03 13:34:18 +00:00
|
|
|
FROM test.hits ANY INNER JOIN
|
2018-08-07 17:08:51 +00:00
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2023-02-03 13:34:18 +00:00
|
|
|
UserID,
|
2018-08-07 17:08:51 +00:00
|
|
|
toInt8(if(yandex > google, yandex / (yandex + google), -google / (yandex + google)) * 10) AS loyalty
|
2021-05-15 09:11:13 +00:00
|
|
|
FROM
|
2018-08-07 17:08:51 +00:00
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2023-02-03 13:34:18 +00:00
|
|
|
UserID,
|
|
|
|
sum(SearchEngineID = 2) AS yandex,
|
2018-08-07 17:08:51 +00:00
|
|
|
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;
|