-- Top DNS answers by number of flows

SELECT
    dns,
    COUNT(*) AS cnt

FROM (
    SELECT
        dns
    FROM
        flow
    ARRAY JOIN
        "dnsAname" AS dns
    WHERE
        notEmpty("dnsAname")
        AND bitTest("dnsStat", 1) = 0  -- Ignore NBNS
        AND "timeFirst" >= {time_from:DateTime64(6)}
        AND "timeLast" <= {time_to:DateTime64(6)}
) AS flows

WHERE dns != ''

GROUP BY dns
ORDER BY cnt DESC

LIMIT {n:UInt64}
