I would like to perform a series of select statements based on the values returned from an initial select statement. Essentially loop through the original values and using the value as a criteria for a new select.
Some pseudo code of what I am trying to do (how I would write this in shell…):
for location in `select places from tablename where XYZ`
do
select new_field from tablename where location = '$location';
done
Here are the selects I really want to run.
Get me a list of Racks:
select regexp_substr("MYTABLE"."Serial_Number" ,'[^ ]+', 1, 3) as "Racks"
from "MYTABLE" "MYTABLE"
where "MYTABLE"."Data_Center" ='SOMEPLACE'
and "MYTABLE"."Device_Type" ='RACK'
and "MYTABLE"."Serial_Number" not like '%WAREHOUSE%'
Print who should own the rack based on count of devices:
select count(*) as count, LOB
from "MYTABLE" "MYTABLE"
where "MYTABLE"."Data_Center" ='SOMEPLACE'
and GRID_LOCATION = '$RACK_from_above' and rownum <= 1 group by LOB order by count desc;
Thanks in advance!
You can readily combine these into a single query: