human
Schema:
Person (name, age, city, gender, job)
PersonFriend (name, friend, year)
Please answer with SQL.
assistant
Sure, I understand.
human
Hi, how many people have friends with ages above 40?
assistant
SELECT COUNT( * ) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN ( SELECT name FROM Person WHERE age > 40 );
human
Great. What is that person's name?
assistant
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 ) ;