CREATE TABLE Person (
    name TEXT PRIMARY KEY,
    age NUMBER,
    city TEXT,
    gender TEXT,
    job TEXT
);
CREATE TABLE PersonFriend (
    name TEXT,
    friend TEXT,
    year NUMBER,
    FOREIGN KEY ("friend") REFERENCES Person("name"),
    FOREIGN KEY ("name") REFERENCES Person("name")
);

Question: How many friends does Dan have?
SQL: SELECT count(T2.friend) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T1.name  =  'Dan'

Question: How many friends does Dan have?
SQL: SELECT count(T2.friend) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T1.name  =  'Dan'

Question: How many females does this network has?
SQL: SELECT count(*) FROM Person WHERE gender  =  'female'

Question: How many females are in the network?
SQL: SELECT count(*) FROM Person WHERE gender  =  'female'

Question: What is the average age for all person?
SQL: SELECT avg(age) FROM Person

Question: What is the average age for all people in the table?
SQL: SELECT avg(age) FROM Person

Question: How many different cities are they from?
SQL: SELECT count(DISTINCT city) FROM Person

Question: How many different cities do people originate from?
SQL: SELECT count(DISTINCT city) FROM Person

Question: How many type of jobs do they have?
SQL: SELECT count(DISTINCT job) FROM Person

Question: How many different jobs are listed?
SQL: SELECT count(DISTINCT job) FROM Person

Question: Who is the oldest person?
SQL: SELECT name FROM Person WHERE age  =  (SELECT max(age) FROM person)

Question: What is the name of the person who is the oldest?
SQL: SELECT name FROM Person WHERE age  =  (SELECT max(age) FROM person)

Question: Who is the oldest person whose job is student?
SQL: SELECT name FROM Person WHERE job  =  'student' AND age  =  (SELECT max(age) FROM person WHERE job  =  'student' )

Question: What is the name of the oldest student?
SQL: SELECT name FROM Person WHERE job  =  'student' AND age  =  (SELECT max(age) FROM person WHERE job  =  'student' )

Question: Who is the youngest male?
SQL: SELECT name FROM Person WHERE gender  =  'male' AND age  =  (SELECT min(age) FROM person WHERE gender  =  'male' )

Question: What is the name of the youngest male?
SQL: SELECT name FROM Person WHERE gender  =  'male' AND age  =  (SELECT min(age) FROM person WHERE gender  =  'male' )

Question: How old is the doctor named Zach?
SQL: SELECT age FROM Person WHERE job  =  'doctor' AND name  =  'Zach'

Question: What is the age of the doctor named Zach?
SQL: SELECT age FROM Person WHERE job  =  'doctor' AND name  =  'Zach'

Question: Who is the person whose age is below 30?
SQL: SELECT name FROM Person WHERE age  <  30

Question: What is the name of the person whose age is below 30?
SQL: SELECT name FROM Person WHERE age  <  30

Question: How many people whose age is greater 30 and job is engineer?
SQL: SELECT count(*) FROM Person WHERE age  >  30 AND job  =  'engineer'

Question: HOw many engineers are older than 30?
SQL: SELECT count(*) FROM Person WHERE age  >  30 AND job  =  'engineer'

Question: What is the average age for each gender?
SQL: SELECT avg(age) ,  gender FROM Person GROUP BY gender

Question: How old is each gender, on average?
SQL: SELECT avg(age) ,  gender FROM Person GROUP BY gender

Question: What is average age for different job title?
SQL: SELECT avg(age) ,  job FROM Person GROUP BY job

Question: How old is the average person for each job?
SQL: SELECT avg(age) ,  job FROM Person GROUP BY job

Question: What is average age of male for different job title?
SQL: SELECT avg(age) ,  job FROM Person WHERE gender  =  'male' GROUP BY job

Question: What is the average age for a male in each job?
SQL: SELECT avg(age) ,  job FROM Person WHERE gender  =  'male' GROUP BY job

Question: What is minimum age for different job title?
SQL: SELECT min(age) ,  job FROM Person GROUP BY job

Question: How old is the youngest person for each job?
SQL: SELECT min(age) ,  job FROM Person GROUP BY job

Question: Find the number of people who is under 40 for each gender.
SQL: SELECT count(*) ,  gender FROM Person WHERE age  <  40 GROUP BY gender

Question: How many people are under 40 for each gender?
SQL: SELECT count(*) ,  gender FROM Person WHERE age  <  40 GROUP BY gender

Question: Find the name of people whose age is greater than any engineer sorted by their age.
SQL: SELECT name FROM Person WHERE age  >  (SELECT min(age) FROM person WHERE job  =  'engineer') ORDER BY age

Question: What is the name of all the people who are older than at least one engineer? Order them by age.
SQL: SELECT name FROM Person WHERE age  >  (SELECT min(age) FROM person WHERE job  =  'engineer') ORDER BY age

Question: Find the number of people whose age is greater than all engineers.
SQL: SELECT count(*) FROM Person WHERE age  >  (SELECT max(age) FROM person WHERE job  =  'engineer')

Question: How many people are older than every engineer?
SQL: SELECT count(*) FROM Person WHERE age  >  (SELECT max(age) FROM person WHERE job  =  'engineer')

Question: list the name, job title of all people ordered by their names.
SQL: SELECT name ,  job FROM Person ORDER BY name

Question: What are the names and job titles of every person ordered alphabetically by name?
SQL: SELECT name ,  job FROM Person ORDER BY name

Question: Find the names of all person sorted in the descending order using age.
SQL: SELECT name FROM Person ORDER BY age DESC

Question: What are the names of everybody sorted by age in descending order?
SQL: SELECT name FROM Person ORDER BY age DESC

Question: Find the name and age of all males in order of their age.
SQL: SELECT name FROM Person WHERE gender  =  'male' ORDER BY age

Question: What is the name and age of every male? Order the results by age.
SQL: SELECT name FROM Person WHERE gender  =  'male' ORDER BY age

Question: Find the name and age of the person who is a friend of both Dan and Alice.
SQL: SELECT T1.name ,  T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend  =  'Dan' INTERSECT SELECT T1.name ,   T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend  =  'Alice'

Question: What are the names and ages of every person who is a friend of both Dan and Alice?
SQL: SELECT T1.name ,  T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend  =  'Dan' INTERSECT SELECT T1.name ,   T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend  =  'Alice'

Question: Find the name and age of the person who is a friend of Dan or Alice.
SQL: SELECT DISTINCT T1.name ,  T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend  =  'Dan' OR T2.friend  =  'Alice'

Question: What are the different names and ages of every friend of either Dan or alice?
SQL: SELECT DISTINCT T1.name ,  T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend  =  'Dan' OR T2.friend  =  'Alice'

Question: Find the name of the person who has friends with age above 40 and under age 30?
SQL: 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) INTERSECT 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  <  30)

Question: What are the names of every person who has a friend over 40 and under 30?
SQL: 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) INTERSECT 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  <  30)