-- Top HTTP user-agent by number of flows

SELECT
    user_agent,
    COUNT(*) AS cnt

FROM (
    SELECT
        user_agent
    FROM
        flow
    ARRAY JOIN
        "httpUsrAg" AS user_agent
    WHERE
        notEmpty("httpUsrAg")
        AND "timeFirst" >= {time_from:DateTime64(6)}
        AND "timeLast" <= {time_to:DateTime64(6)}
) AS flows

GROUP BY user_agent
ORDER BY cnt DESC

LIMIT {n:UInt64}
