human
Schema:
Person (name, age, city, gender, job)
PersonFriend (name, friend, year)
Please answer with SQL.
assistant
Sure, I understand.
human
What is the average age of all people?
assistant
SELECT AVG ( age ) FROM person;
human
What is the average age of the friends?
assistant
SELECT AVG ( t1.age ) FROM person AS t1 JOIN personfriend AS t2 ON t1.name = t2.friend;
human
Show the average friend age for each person.
assistant
SELECT T2.name , AVG ( T1.age ) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend GROUP BY T2.name;
human
Who has the highest?
assistant
SELECT T2.name , AVG ( T1.age ) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend GROUP BY T2.name ORDER BY AVG ( T1.age ) DESC LIMIT 1 ;