CREATE TABLE agg_deserialize ( t DateTime, v1 AggregateFunction(avgState, UInt64), v2 AggregateFunction(argMax, UInt64, DateTime) ) ENGINE = MergeTree() ORDER BY t INSERT INTO agg_deserialize SELECT now() + number AS t, initializeAggregation('avgState', number), initializeAggregation('argMaxState', number, t) FROM numbers(50000000) SELECT v1 FROM agg_deserialize FORMAT Null SELECT toStartOfHour(t) AS h, avgMerge(v1) FROM agg_deserialize GROUP BY h FORMAT Null SELECT v2 FROM agg_deserialize FORMAT Null SELECT toStartOfHour(t) AS h, argMaxMerge(v2) FROM agg_deserialize GROUP BY h FORMAT Null DROP TABLE IF EXISTS agg_deserialize