CREATE TABLE has_allergy (stuid NUMBER, allergy CLOB)
CREATE TABLE student (stuid NUMBER, lname CLOB, fname CLOB, age NUMBER, sex CLOB, major NUMBER, advisor NUMBER, city_code CLOB)
CREATE TABLE allergy_type (allergy CLOB, allergytype CLOB)

How old are the students with allergies to food and animal types on average?
SELECT AVG(age) FROM student WHERE stuid IN (SELECT T1.stuid FROM has_allergy AS T1 JOIN allergy_type AS T2 ON T1.allergy = T2.allergy WHERE T2.allergytype = "food" INTERSECT SELECT T1.stuid FROM has_allergy AS T1 JOIN allergy_type AS T2 ON T1.allergy = T2.allergy WHERE T2.allergytype = "animal")
WITH "_u_0" AS (SELECT ARRAY_AGG("stuid") AS "", "T2"."allergytype" AS "_u_1" FROM "has_allergy" "T1" JOIN "allergy_type" "T2" ON "T1"."allergy" = "T2"."allergy" GROUP BY "T2"."allergytype") SELECT AVG("age") FROM "student" LEFT JOIN "_u_0" "_u_0" ON "_u_0"."_u_1" = "food" WHERE ARRAY_ANY("_u_0"."", "_x" -> "stuid" = "_x")