human
Schema:
Person (name, age, city, gender, job)
PersonFriend (name, friend, year)
Please answer with SQL.
assistant
Sure, I understand.
human
Show how many friends each person in the set has.
assistant
SELECT name , COUNT( * ) FROM personfriend GROUP BY name;
human
Who has the most friends?
assistant
SELECT name FROM personfriend GROUP BY name ORDER BY COUNT( * ) DESC LIMIT 1;
human
Who is friends with someone who is above 40?
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 ) ;