# Passing output from subqueries

**URL:** https://discuss.prometheus.io/t/passing-output-from-subqueries/1772
**Category:** PromQL
**Created:** [July 26, 2023, 1:31pm UTC](https://discuss.prometheus.io/t/passing-output-from-subqueries/1772 "2023-07-26T13:31:30Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![sunilsunderrajdev](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/sunilsunderrajdev/32/755_2.png) [@sunilsunderrajdev](https://discuss.prometheus.io/u/sunilsunderrajdev)
#### Post date: [July 26, 2023, 1:31pm UTC](https://discuss.prometheus.io/t/passing-output-from-subqueries/1772/1 "2023-07-26T13:31:30Z")

</div>

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
