select src_ip, dst_ip, SUM(pack_size) AS value, toStartOfInterval(create_time, INTERVAL 15 minute) AS time from tableA where create_time >= '2022-11-1716:15:00' and create_time< '2022-11-1717:20:00' group by 4, 1, 2 order by 4, 3 desc
SELECT u.ct, untuple( arrayJoin( arraySlice( arraySort( (x, y)->- y, arrayMap( (x, y, z) -> (x, y, z), groupArray(u.src_ip), groupArray(u.dst_ip), groupArray(u.p) ), groupArray(u.p) ), 1, 25 ) ) ) AS res FROM ( SELECT toStartOfInterval(create_time, INTERVAL 1 minute) AS ct, src_ip, dst_ip, SUM(pack_size) AS p FROM `tableA` WHERE create_time < FROM_UNIXTIME(1668700800) AND create_time >= FROM_UNIXTIME(1668672000) GROUPBY src_ip, dst_ip, ct ) as u GROUPBY `ct` ORDERBY ct
SELECT toStartOfInterval(create_time, INTERVAL 1 minute) AS ct, src_ip, dst_ip, SUM(pack_size) AS p FROM flora.gopacket WHERE create_time < FROM_UNIXTIME(1676455200) AND create_time >= FROM_UNIXTIME(1676433600) GROUP BY src_ip, dst_ip, ct ORDER BY ct, p DESC LIMIT 25 BY ct
这个功能就是相当于在排序完成之后,对于每个ct,取前25个值。因为之前已经ORDER BY p DESC了,所以可以获得前25个值最大的p。