human
Schema:
Person (name, age, city, gender, job)
PersonFriend (name, friend, year)
Please answer with SQL.
assistant
Sure, I understand.
human
How many people are there?
assistant
SELECT COUNT( * ) FROM person;
human
How many are younger than the average age?
assistant
SELECT COUNT( * ) FROM person WHERE age < ( SELECT AVG ( age ) FROM person );
human
What about older?
assistant
SELECT COUNT( * ) FROM person WHERE age > ( SELECT AVG ( age ) FROM person );
human
Who is friends with these people? Show their names and ages.
assistant
SELECT DISTINCT T2.name , T2.friend , T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.age > ( SELECT AVG ( age ) FROM person ) ;