combining groupBy in tickscript


I have a script like following

   |query('SELECT sum("value") FROM "app"."autogen"."measurement" WHERE ' + 
       'product = \'' + product + '\'')
       .warn(lambda: 0 < 1)
       .message(message + ' {{.Group}}')

It calls alert node for every unique event_type as given in documentation. But I want to combine it somehow. for me event_type has types like 404, 400, 401, total_request etc (these are variable) and i want to find percentage of 404, 400, 401 and then say
if percentage(404) > x and percentage(400) < y and percentage(401) > 0 then push something to influxdb different measure. (percentage(x) = sum(x)/total_requests*100)

And in order to do this i need to have access to all those sum('value') of all event_types in the same node at same time so that can use it in my usecase. One way i found was to get all data without groupBy and then find different sums on kapacitor side. but it ends up retrieving 100k+ values which is waste.

So what would be other way of doing it ?

Thanks !