Generate one table for each row of another table

I’m currently trying to solve a problem with Flux and SQL. I have a SQL Database, where I’m filtering for a specific criteria, which corresponds to multiple Sensors with a SensorID each and one or many portnumber(s). The data of the sensors is written to the InfluxDB via a Telegraf Client and identified by the SensorID and the portnumber. I already have the call to the SQL DB in Flux. Imagine the following Table as a result:

Port SensorID
37 31011
38 31011
39 44522
40 44522

Now, I normally would do something like this:

from(bucket: "Sensors")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "SomeValue")
  |> filter(fn: (r) => r["SensorID"] == "31011")
  |> filter(fn: (r) => r["_field"] == "37")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

…but instead of the fixed values for the SensorID and the _field (portnumber), I would like to iterate over each row of the first table and insert the values for the SensorID and _field (portnumber) dynamically, so I can see all datastreams (in this case four) in the resulting table. Is there an easy way to achieve this?