-- Top Know HASSH Signatures by number of flows

SELECT
    hassh,
    hasshDesc,
    COUNT(*) AS cnt

FROM (
    SELECT
        hassh,
        hasshDesc
    FROM
        flow
    ARRAY JOIN
        "sshHassh" AS hassh,
        "sshHasshDesc" AS hasshDesc
    WHERE
        notEmpty("sshHasshDesc")
        AND "timeFirst" >= {time_from:DateTime64(6)}
        AND "timeLast" <= {time_to:DateTime64(6)}
) AS flows

GROUP BY hassh, hasshDesc
ORDER BY cnt DESC

LIMIT {n:UInt64}
