mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
8b438bcd3c
Fix trailing whitespaces in FROM/IN clause with subqueries in multiline mode, and also changes the output of the queries slightly in a more human friendly way. Before: $ clickhouse-format <<<'select * from system.one, (select * from system.one)' SELECT * FROM system.one , ( SELECT * FROM system.one ) After: $ clickhouse-format <<<'select * from system.one, (select * from system.one)' SELECT * FROM system.one, ( SELECT * FROM system.one ) v2: Fix subqueries formatting in a different way v3: Adjust *.reference in tests v4: Fix modernize-loop-convert in ASTTablesInSelectQuery
98 lines
2.2 KiB
SQL
98 lines
2.2 KiB
SQL
SET any_join_distinct_right_table_keys = 1;
|
|
SET joined_subquery_requires_alias = 0;
|
|
|
|
SELECT
|
|
loyalty,
|
|
count()
|
|
FROM test.hits ANY LEFT JOIN
|
|
(
|
|
SELECT
|
|
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
|
|
loyalty,
|
|
count()
|
|
FROM
|
|
(
|
|
SELECT UserID
|
|
FROM test.hits
|
|
) ANY LEFT JOIN
|
|
(
|
|
SELECT
|
|
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
|
|
loyalty,
|
|
count()
|
|
FROM
|
|
(
|
|
SELECT
|
|
loyalty,
|
|
UserID
|
|
FROM
|
|
(
|
|
SELECT UserID
|
|
FROM test.hits
|
|
) ANY LEFT JOIN
|
|
(
|
|
SELECT
|
|
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
|
|
loyalty,
|
|
count() AS c,
|
|
bar(log(c + 1) * 1000, 0, log(3000000) * 1000, 80)
|
|
FROM test.hits ANY INNER JOIN
|
|
(
|
|
SELECT
|
|
UserID,
|
|
toInt8(if(yandex > google, yandex / (yandex + google), -google / (yandex + google)) * 10) AS loyalty
|
|
FROM
|
|
(
|
|
SELECT
|
|
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;
|