Passing output from subqueries

I have a subquery use case
Get a list of servers from a metric and loop through that list in another query

This query works if I hard code the hostname say “H1”
(2 - ((avg(host_availability{host=“H1”}) < bool 99.9) + (avg(host_availability{} and on (host) avg_over_time(failover_host{primaryhost=“H1”}[24h])) < bool 99.9))) == bool 0

I am trying to write a recording rule to run the above for all hosts but am unable get it working.
I have the hosts in another metric
khosts{} - with label host