aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/select/host_count.sql
blob: eed3d6c9fa644ee3294b1ba46190c04217eb025d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* postgres can not */
USE plato;

$data = (
    SELECT
        Url::Normalize(url) AS normalized_url,
        Url::GetHost(Url::Normalize(url)) AS host,
        Url::GetDomain(Url::Normalize(url), 1) AS tld
    FROM CONCAT(
        `Input1`,
        `Input2`
    )
);
$ru_hosts = (
    SELECT
        tld,
        host
    FROM
        $data
    WHERE normalized_url IS NOT NULL AND (
           tld = "ru"
        OR tld = "su"
        OR tld = "рф"
        OR tld = "xn--p1ai" -- punycode рф
    )
);

SELECT
    tld,
    COUNT(DISTINCT host) AS hosts_count
FROM $ru_hosts
GROUP BY tld
ORDER BY hosts_count DESC;