human
Schema:
Person (name, age, city, gender, job)
PersonFriend (name, friend, year)
Please answer with SQL.
assistant
Sure, I understand.
human
Who has exactly 1 friend?
assistant
SELECT name FROM personfriend GROUP BY name HAVING COUNT( * ) = 1;
human
What about more than 1?
assistant
SELECT name FROM personfriend GROUP BY name HAVING COUNT( * ) > 1;
human
Who has a friend who is at least 40 years old?
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 ) ;