-- Top applications by number of flows

SELECT
    toValidUTF8(splitByChar('.', "nDPIclass")[1]) AS appl,
    COUNT(*) AS cnt
FROM
    flow
WHERE
    "timeFirst" >= {time_from:DateTime64(6)}
    AND "timeLast" <= {time_to:DateTime64(6)}

GROUP BY appl
ORDER BY multiply(cnt, {sort_order:Int8})

LIMIT {n:UInt64}
