NODE aggregate SQL > SELECT toDate(toTimeZone(fromUnixTimestamp64Milli(fetched_at), 'UTC')) AS day, component_id, argMaxState(indicator, toUInt8(multiIf(indicator = 'critical', 3, indicator = 'major', 2, indicator = 'minor', 1, 0))) AS worst_indicator, maxState(toUInt8(status = 'under_maintenance')) AS had_maintenance, sumState(toUInt32(1)) AS snapshot_count FROM external_status_component__v0 GROUP BY day, component_id TYPE materialized DATASOURCE mv__external_status_component_daily__v0