提交 322e0ef4 编写于 作者: A Alexey Milovidov

Added a test from George #728

上级 69e8133f
{"total":"1","domain":"baidu.com"}
{"total":"2","domain":"facebook.com"}
{"total":"1","domain":"google.com"}
{"total":"2","domain":"yandex.ru"}
{"total":"1","domain":"baidu.com"}
{"total":"2","domain":"facebook.com"}
{"total":"1","domain":"google.com"}
{"total":"2","domain":"yandex.ru"}
1 baidu.com
2 facebook.com
1 google.com
2 yandex.ru
1 baidu.com
2 facebook.com
1 google.com
2 yandex.ru
1 baidu.com
1 google.com
2 facebook.com
2 yandex.ru
1
1
2
2
baidu.com
google.com
facebook.com
yandex.ru
DROP TABLE IF EXISTS test.clicks;
DROP TABLE IF EXISTS test.transactions;
CREATE TABLE test.clicks (domain String) ENGINE = Memory;
CREATE TABLE test.transactions (domain String) ENGINE = Memory;
INSERT INTO test.clicks VALUES ('facebook.com'), ('yandex.ru'), ('google.com');
INSERT INTO test.transactions VALUES ('facebook.com'), ('yandex.ru'), ('baidu.com');
SELECT
sum(total_count) AS total,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
FORMAT JSONEachRow;
SELECT
sum(total_count) AS total,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
FORMAT JSONEachRow;
SELECT DISTINCT * FROM
(
SELECT
sum(total_count) AS total,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
UNION ALL
SELECT
sum(total_count) AS total,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
);
SELECT DISTINCT total, domain FROM
(
SELECT
sum(total_count) AS total,
sum(facebookHits) AS facebook,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
UNION ALL
SELECT
sum(total_count) AS total,
max(facebookHits) AS facebook,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
)
ORDER BY domain, total;
SELECT * FROM
(
SELECT
sum(total_count) AS total,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
)
ALL FULL OUTER JOIN
(
SELECT
sum(total_count) AS total,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
)
USING (total, domain)
ORDER BY total, domain;
SELECT total FROM
(
SELECT
sum(total_count) AS total,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
)
ALL FULL OUTER JOIN
(
SELECT
sum(total_count) AS total,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
)
USING (total, domain)
ORDER BY total, domain;
SELECT domain FROM
(
SELECT
sum(total_count) AS total,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
)
ALL FULL OUTER JOIN
(
SELECT
sum(total_count) AS total,
domain
FROM
(
SELECT
COUNT(*) AS total_count,
SUM(if(domain = 'facebook.com', 1, 0)) AS facebookHits,
domain
FROM test.clicks
GROUP BY domain
UNION ALL
SELECT
COUNT(*) AS total_count,
toUInt64(0) AS facebookHits,
domain
FROM test.transactions
GROUP BY domain
)
GROUP BY domain
ORDER BY domain
LIMIT 10
)
USING (total, domain)
ORDER BY total, domain;
DROP TABLE test.clicks;
DROP TABLE test.transactions;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册