CREATE TABLE personfriend (name CLOB, friend CLOB, year NUMBER)
CREATE TABLE person (name CLOB, age NUMBER, city CLOB, gender CLOB, job CLOB)

Find the name of the person who has friends with age above 40 and under age 30?
SELECT T1.name FROM person AS T1 JOIN personfriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM person WHERE age > 40) INTERSECT SELECT T1.name FROM person AS T1 JOIN personfriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM person WHERE age < 30)
SELECT "T1"."name" FROM "person" "T1" JOIN "personfriend" "T2" ON "T1"."name" = "T2"."name" AND "T2"."friend" IN (SELECT "name" FROM "person" WHERE "age" > 40) INTERSECT SELECT "T1"."name" FROM "person" "T1" JOIN "personfriend" "T2" ON "T1"."name" = "T2"."name" AND "T2"."friend" IN (SELECT "name" FROM "person" WHERE "age" < 30)