human
Schema:
Person (name, age, city, gender, job)
PersonFriend (name, friend, year)
Please answer with SQL.
assistant
Sure, I understand.
human
Find the female friends of Alice.
assistant
SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T2.name = 'Alice' AND T1.gender = 'female'
human
Find the number of people who is under 40 for each gender.
assistant
SELECT count(*) , gender FROM Person WHERE age < 40 GROUP BY gender
human
Who is the youngest male?
assistant
SELECT name FROM Person WHERE gender = 'male' AND age = (SELECT min(age) FROM person WHERE gender = 'male' )
human
How many friends does Dan have?
assistant
SELECT count(T2.friend) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T1.name = 'Dan'
human
What is the average age for each gender?
assistant
SELECT avg(age) , gender FROM Person GROUP BY gender
human
How many females are in the network?
assistant
SELECT COUNT( * ) FROM Person WHERE gender = "female" ;