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
|
2018-08-07 17:08:51 +00:00
|
|
|
loyalty,
|
|
|
|
count()
|
|
|
|
FROM test.hits ANY LEFT JOIN
|
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2018-08-07 17:08:51 +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;
|
|
|
|
|
|
|
|
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2018-08-07 17:08:51 +00:00
|
|
|
loyalty,
|
|
|
|
count()
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT UserID
|
|
|
|
FROM test.hits
|
|
|
|
) ANY LEFT JOIN
|
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2018-08-07 17:08:51 +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;
|
|
|
|
|
|
|
|
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2018-08-07 17:08:51 +00:00
|
|
|
loyalty,
|
|
|
|
count()
|
|
|
|
FROM
|
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2018-08-07 17:08:51 +00:00
|
|
|
loyalty,
|
|
|
|
UserID
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT UserID
|
|
|
|
FROM test.hits
|
|
|
|
) ANY LEFT JOIN
|
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2018-08-07 17:08:51 +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;
|
|
|
|
|
|
|
|
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2018-08-07 17:08:51 +00:00
|
|
|
loyalty,
|
|
|
|
count() AS c,
|
|
|
|
bar(log(c + 1) * 1000, 0, log(3000000) * 1000, 80)
|
|
|
|
FROM test.hits ANY INNER JOIN
|
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2018-08-07 17:08:51 +00:00
|
|
|
UserID,
|
|
|
|
toInt8(if(yandex > google, yandex / (yandex + google), -google / (yandex + google)) * 10) AS loyalty
|
|
|
|
FROM
|
|
|
|
(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2018-08-07 17:08:51 +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;
|