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

Find the average age of the students who have allergies with food and animal types.
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" AS "T1" JOIN "allergy_type" AS "T2" ON "T1"."allergy" = "T2"."allergy" GROUP BY "T2"."allergytype") SELECT AVG("age") FROM "student" LEFT JOIN "_u_0" AS "_u_0" ON "_u_0"."_u_1" = "food" WHERE ARRAY_ANY("_u_0"."", "_x" -> "stuid" = "_x")