Input:
[INST] Here is a database schema:
Document_Types :
document_type_code [ TEXT ] primary_key
document_description [ TEXT ]

Documents :
document_id [ INT ] primary_key
document_type_code [ TEXT ] Documents.document_type_code = Document_Types.document_type_code
grant_id [ INT ] Documents.grant_id = Grants.grant_id
sent_date [ TEXT ]
response_received_date [ TEXT ]
other_details [ TEXT ]

Grants :
grant_id [ INT ] primary_key
organisation_id [ INT ] Grants.organisation_id = Organisations.organisation_id
grant_amount [ INT ]
grant_start_date [ TEXT ]
grant_end_date [ TEXT ]
other_details [ TEXT ]

Organisation_Types :
organisation_type [ TEXT ] primary_key
organisation_type_description [ TEXT ]

Organisations :
organisation_id [ INT ] primary_key
organisation_type [ TEXT ] Organisations.organisation_type = Organisation_Types.organisation_type
organisation_details [ TEXT ]

Project_Outcomes :
project_id [ INT ] Project_Outcomes.project_id = Projects.project_id
outcome_code [ TEXT ] Project_Outcomes.outcome_code = Research_Outcomes.outcome_code
outcome_details [ TEXT ]

Project_Staff :
staff_id [ INT ] primary_key
project_id [ INT ] Project_Staff.project_id = Projects.project_id
role_code [ TEXT ] Project_Staff.role_code = Staff_Roles.role_code
date_from [ TEXT ]
date_to [ TEXT ]
other_details [ TEXT ]

Projects :
project_id [ INT ] primary_key
organisation_id [ INT ] Projects.organisation_id = Organisations.organisation_id
project_details [ TEXT ]

Research_Outcomes :
outcome_code [ TEXT ] primary_key
outcome_description [ TEXT ]

Research_Staff :
staff_id [ INT ] primary_key
employer_organisation_id [ INT ] Research_Staff.employer_organisation_id = Organisations.organisation_id
staff_details [ TEXT ]

Staff_Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Tasks :
task_id [ INT ] primary_key
project_id [ INT ] Tasks.project_id = Projects.project_id
task_details [ TEXT ]
eg Agree Objectives [ TEXT ]

Please write me a SQL statement that answers the following question: What is the most common role for the staff? [/INST]

Output: SELECT role_code FROM Project_Staff GROUP BY role_code ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many friends does Dan have? [/INST]

Output: SELECT count(T2.friend) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T1.name  =  'Dan';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many friends does Dan have? [/INST]

Output: SELECT count(T2.friend) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T1.name  =  'Dan';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many females does this network has? [/INST]

Output: SELECT count(*) FROM Person WHERE gender  =  'female';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many females are in the network? [/INST]

Output: SELECT count(*) FROM Person WHERE gender  =  'female';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the average age for all person? [/INST]

Output: SELECT avg(age) FROM Person;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the average age for all people in the table? [/INST]

Output: SELECT avg(age) FROM Person;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many different cities are they from? [/INST]

Output: SELECT count(DISTINCT city) FROM Person;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many different cities do people originate from? [/INST]

Output: SELECT count(DISTINCT city) FROM Person;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many type of jobs do they have? [/INST]

Output: SELECT count(DISTINCT job) FROM Person;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many different jobs are listed? [/INST]

Output: SELECT count(DISTINCT job) FROM Person;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who is the oldest person? [/INST]

Output: SELECT name FROM Person WHERE age  =  (SELECT max(age) FROM person);


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the name of the person who is the oldest? [/INST]

Output: SELECT name FROM Person WHERE age  =  (SELECT max(age) FROM person);


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who is the oldest person whose job is student? [/INST]

Output: SELECT name FROM Person WHERE job  =  'student' AND age  =  (SELECT max(age) FROM person WHERE job  =  'student' );


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the name of the oldest student? [/INST]

Output: SELECT name FROM Person WHERE job  =  'student' AND age  =  (SELECT max(age) FROM person WHERE job  =  'student' );


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who is the youngest male? [/INST]

Output: SELECT name FROM Person WHERE gender  =  'male' AND age  =  (SELECT min(age) FROM person WHERE gender  =  'male' );


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the name of the youngest male? [/INST]

Output: SELECT name FROM Person WHERE gender  =  'male' AND age  =  (SELECT min(age) FROM person WHERE gender  =  'male' );


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How old is the doctor named Zach? [/INST]

Output: SELECT age FROM Person WHERE job  =  'doctor' AND name  =  'Zach';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the age of the doctor named Zach? [/INST]

Output: SELECT age FROM Person WHERE job  =  'doctor' AND name  =  'Zach';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who is the person whose age is below 30? [/INST]

Output: SELECT name FROM Person WHERE age  <  30;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the name of the person whose age is below 30? [/INST]

Output: SELECT name FROM Person WHERE age  <  30;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many people whose age is greater 30 and job is engineer? [/INST]

Output: SELECT count(*) FROM Person WHERE age  >  30 AND job  =  'engineer';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: HOw many engineers are older than 30? [/INST]

Output: SELECT count(*) FROM Person WHERE age  >  30 AND job  =  'engineer';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the average age for each gender? [/INST]

Output: SELECT avg(age) ,  gender FROM Person GROUP BY gender;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How old is each gender, on average? [/INST]

Output: SELECT avg(age) ,  gender FROM Person GROUP BY gender;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is average age for different job title? [/INST]

Output: SELECT avg(age) ,  job FROM Person GROUP BY job;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How old is the average person for each job? [/INST]

Output: SELECT avg(age) ,  job FROM Person GROUP BY job;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is average age of male for different job title? [/INST]

Output: SELECT avg(age) ,  job FROM Person WHERE gender  =  'male' GROUP BY job;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the average age for a male in each job? [/INST]

Output: SELECT avg(age) ,  job FROM Person WHERE gender  =  'male' GROUP BY job;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is minimum age for different job title? [/INST]

Output: SELECT min(age) ,  job FROM Person GROUP BY job;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How old is the youngest person for each job? [/INST]

Output: SELECT min(age) ,  job FROM Person GROUP BY job;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the number of people who is under 40 for each gender. [/INST]

Output: SELECT count(*) ,  gender FROM Person WHERE age  <  40 GROUP BY gender;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many people are under 40 for each gender? [/INST]

Output: SELECT count(*) ,  gender FROM Person WHERE age  <  40 GROUP BY gender;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the name of people whose age is greater than any engineer sorted by their age. [/INST]

Output: SELECT name FROM Person WHERE age  >  (SELECT min(age) FROM person WHERE job  =  'engineer') ORDER BY age;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the name of all the people who are older than at least one engineer? Order them by age. [/INST]

Output: SELECT name FROM Person WHERE age  >  (SELECT min(age) FROM person WHERE job  =  'engineer') ORDER BY age;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the number of people whose age is greater than all engineers. [/INST]

Output: SELECT count(*) FROM Person WHERE age  >  (SELECT max(age) FROM person WHERE job  =  'engineer');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: How many people are older than every engineer? [/INST]

Output: SELECT count(*) FROM Person WHERE age  >  (SELECT max(age) FROM person WHERE job  =  'engineer');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: list the name, job title of all people ordered by their names. [/INST]

Output: SELECT name ,  job FROM Person ORDER BY name;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names and job titles of every person ordered alphabetically by name? [/INST]

Output: SELECT name ,  job FROM Person ORDER BY name;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the names of all person sorted in the descending order using age. [/INST]

Output: SELECT name FROM Person ORDER BY age DESC;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of everybody sorted by age in descending order? [/INST]

Output: SELECT name FROM Person ORDER BY age DESC;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the name and age of all males in order of their age. [/INST]

Output: SELECT name FROM Person WHERE gender  =  'male' ORDER BY age;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the name and age of every male? Order the results by age. [/INST]

Output: SELECT name FROM Person WHERE gender  =  'male' ORDER BY age;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the name and age of the person who is a friend of both Dan and Alice. [/INST]

Output: 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';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names and ages of every person who is a friend of both Dan and Alice? [/INST]

Output: 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';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the name and age of the person who is a friend of Dan or Alice. [/INST]

Output: 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';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the different names and ages of every friend of either Dan or alice? [/INST]

Output: 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';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the name of the person who has friends with age above 40 and under age 30? [/INST]

Output: 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);


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of every person who has a friend over 40 and under 30? [/INST]

Output: 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);


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the name of the person who has friends with age above 40 but not under age 30? [/INST]

Output: 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) EXCEPT 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);


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of the people who are older 40 but no friends under age 30? [/INST]

Output: 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) EXCEPT 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);


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the name of the person who has no student friends. [/INST]

Output: SELECT name FROM person EXCEPT SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T1.job  =  'student';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of the people who have no friends who are students? [/INST]

Output: SELECT name FROM person EXCEPT SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T1.job  =  'student';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the person who has exactly one friend. [/INST]

Output: SELECT name FROM PersonFriend GROUP BY name HAVING count(*)  =  1;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of everybody who has exactly one friend? [/INST]

Output: SELECT name FROM PersonFriend GROUP BY name HAVING count(*)  =  1;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who are the friends of Bob? [/INST]

Output: SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T1.name  =  'Bob';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who are Bob's friends? [/INST]

Output: SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T1.name  =  'Bob';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the name of persons who are friends with Bob. [/INST]

Output: SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend  =  'Bob';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of all of Bob's friends? [/INST]

Output: SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend  =  'Bob';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the names of females who are friends with Zach [/INST]

Output: SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend  =  'Zach' AND T1.gender  =  'female';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of all females who are friends with Zach? [/INST]

Output: SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend  =  'Zach' AND T1.gender  =  'female';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the female friends of Alice. [/INST]

Output: SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T2.name  =  'Alice' AND T1.gender  =  'female';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are all the friends of Alice who are female? [/INST]

Output: SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T2.name  =  'Alice' AND T1.gender  =  'female';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the male friend of Alice whose job is a doctor? [/INST]

Output: SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T2.name  =  'Alice' AND T1.gender  =  'male' AND T1.job  =  'doctor';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who are the friends of Alice that are doctors? [/INST]

Output: SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T2.name  =  'Alice' AND T1.gender  =  'male' AND T1.job  =  'doctor';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who has a friend that is from new york city? [/INST]

Output: SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T1.city  =  'new york city';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of all friends who are from New York? [/INST]

Output: SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T1.city  =  'new york city';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who has friends that are younger than the average age? [/INST]

Output: SELECT DISTINCT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T1.age  <  (SELECT avg(age) FROM person);


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the different names of friends who are younger than the average age for a friend? [/INST]

Output: SELECT DISTINCT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T1.age  <  (SELECT avg(age) FROM person);


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who has friends that are older than the average age? Print their friends and their ages as well [/INST]

Output: 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);


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Whare the names, friends, and ages of all people who are older than the average age of a person? [/INST]

Output: 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);


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who is the friend of Zach with longest year relationship? [/INST]

Output: SELECT friend FROM PersonFriend WHERE name =  'Zach' AND YEAR  =  (SELECT max(YEAR) FROM PersonFriend WHERE name =  'Zach');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Which friend of Zach has the longest-lasting friendship? [/INST]

Output: SELECT friend FROM PersonFriend WHERE name =  'Zach' AND YEAR  =  (SELECT max(YEAR) FROM PersonFriend WHERE name =  'Zach');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the age of the friend of Zach with longest year relationship? [/INST]

Output: SELECT T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T2.name =  'Zach' AND T2.year  =  (SELECT max(YEAR) FROM PersonFriend WHERE name =  'Zach');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the ages of all of Zach's friends who are in the longest relationship? [/INST]

Output: SELECT T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.friend WHERE T2.name =  'Zach' AND T2.year  =  (SELECT max(YEAR) FROM PersonFriend WHERE name =  'Zach');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the name of persons who are friends with Alice for the shortest years. [/INST]

Output: SELECT name FROM PersonFriend WHERE friend =  'Alice' AND YEAR  =  (SELECT min(YEAR) FROM PersonFriend WHERE friend =  'Alice');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of all people who are friends with Alice for the shortest amount of time? [/INST]

Output: SELECT name FROM PersonFriend WHERE friend =  'Alice' AND YEAR  =  (SELECT min(YEAR) FROM PersonFriend WHERE friend =  'Alice');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find the name, age, and job title of persons who are friends with Alice for the longest years. [/INST]

Output: SELECT T1.name ,  T1.age ,  T1.job FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend =  'Alice' AND T2.year  =  (SELECT max(YEAR) FROM PersonFriend WHERE friend =  'Alice');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names, ages, and jobs of all people who are friends with Alice for the longest amount of time? [/INST]

Output: SELECT T1.name ,  T1.age ,  T1.job FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name  =  T2.name WHERE T2.friend =  'Alice' AND T2.year  =  (SELECT max(YEAR) FROM PersonFriend WHERE friend =  'Alice');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Who is the person that has no friend? [/INST]

Output: SELECT name FROM person EXCEPT SELECT name FROM PersonFriend;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of all people who do not have friends? [/INST]

Output: SELECT name FROM person EXCEPT SELECT name FROM PersonFriend;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Which person whose friends have the oldest average age? [/INST]

Output: 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;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the name of the person who has the oldest average age for their friends, and what is that average age? [/INST]

Output: 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;


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the total number of people who has no friend living in the city of Austin. [/INST]

Output: SELECT count(DISTINCT name) FROM PersonFriend WHERE friend NOT IN (SELECT name FROM person WHERE city  =  'Austin');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What is the total number of people who have no friends living in Austin? [/INST]

Output: SELECT count(DISTINCT name) FROM PersonFriend WHERE friend NOT IN (SELECT name FROM person WHERE city  =  'Austin');


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: Find Alice's friends of friends. [/INST]

Output: SELECT DISTINCT T4.name FROM PersonFriend AS T1 JOIN Person AS T2 ON T1.name  =  T2.name JOIN PersonFriend AS T3 ON T1.friend  =  T3.name JOIN PersonFriend AS T4 ON T3.friend  =  T4.name WHERE T2.name  =  'Alice' AND T4.name != 'Alice';


Input:
[INST] Here is a database schema:
Person :
name [ TEXT ] primary_key
age [ INT ]
city [ TEXT ]
gender [ TEXT ]
job [ TEXT ]

PersonFriend :
name [ TEXT ] PersonFriend.name = Person.name
friend [ TEXT ] PersonFriend.friend = Person.name
year [ INT ]

Please write me a SQL statement that answers the following question: What are the names of all of Alice's friends of friends? [/INST]

Output: SELECT DISTINCT T4.name FROM PersonFriend AS T1 JOIN Person AS T2 ON T1.name  =  T2.name JOIN PersonFriend AS T3 ON T1.friend  =  T3.name JOIN PersonFriend AS T4 ON T3.friend  =  T4.name WHERE T2.name  =  'Alice' AND T4.name != 'Alice';


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: How many members are there? [/INST]

Output: SELECT count(*) FROM member;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: List the names of members in ascending alphabetical order. [/INST]

Output: SELECT Name FROM member ORDER BY Name ASC;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: What are the names and countries of members? [/INST]

Output: SELECT Name ,  Country FROM member;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Show the names of members whose country is "United States" or "Canada". [/INST]

Output: SELECT Name FROM member WHERE Country  =  "United States" OR Country  =  "Canada";


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Show the different countries and the number of members from each. [/INST]

Output: SELECT Country ,  COUNT(*) FROM member GROUP BY Country;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Show the most common country across members. [/INST]

Output: SELECT Country FROM member GROUP BY Country ORDER BY COUNT(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Which countries have more than two members? [/INST]

Output: SELECT Country FROM member GROUP BY Country HAVING COUNT(*)  >  2;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Show the leader names and locations of colleges. [/INST]

Output: SELECT Leader_Name ,  College_Location FROM college;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Show the names of members and names of colleges they go to. [/INST]

Output: SELECT T2.Name ,  T1.Name FROM college AS T1 JOIN member AS T2 ON T1.College_ID  =  T2.College_ID;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Show the names of members and the locations of colleges they go to in ascending alphabetical order of member names. [/INST]

Output: SELECT T2.Name ,  T1.College_Location FROM college AS T1 JOIN member AS T2 ON T1.College_ID  =  T2.College_ID ORDER BY T2.Name ASC;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Show the distinct leader names of colleges associated with members from country "Canada". [/INST]

Output: SELECT DISTINCT T1.Leader_Name FROM college AS T1 JOIN member AS T2 ON T1.College_ID  =  T2.College_ID WHERE T2.Country  =  "Canada";


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Show the names of members and the decoration themes they have. [/INST]

Output: SELECT T1.Name ,  T2.Decoration_Theme FROM member AS T1 JOIN round AS T2 ON T1.Member_ID  =  T2.Member_ID;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Show the names of members that have a rank in round higher than 3. [/INST]

Output: SELECT T1.Name FROM member AS T1 JOIN round AS T2 ON T1.Member_ID  =  T2.Member_ID WHERE T2.Rank_in_Round  >  3;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: Show the names of members in ascending order of their rank in rounds. [/INST]

Output: SELECT T1.Name FROM member AS T1 JOIN round AS T2 ON T1.Member_ID  =  T2.Member_ID ORDER BY Rank_in_Round ASC;


Input:
[INST] Here is a database schema:
college :
College_ID [ INT ] primary_key
Name [ TEXT ]
Leader_Name [ TEXT ]
College_Location [ TEXT ]

member :
Member_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
College_ID [ INT ] member.College_ID = college.College_ID

round :
Round_ID [ INT ]
Member_ID [ INT ] primary_key round.Member_ID = member.Member_ID
Decoration_Theme [ TEXT ]
Rank_in_Round [ INT ]

Please write me a SQL statement that answers the following question: List the names of members who did not participate in any round. [/INST]

Output: SELECT Name FROM member WHERE Member_ID NOT IN (SELECT Member_ID FROM round);


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Find the name and access counts of all documents, in alphabetic order of the document name. [/INST]

Output: SELECT document_name ,  access_count FROM documents ORDER BY document_name;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What are the names of all the documents, as well as the access counts of each, ordered alphabetically? [/INST]

Output: SELECT document_name ,  access_count FROM documents ORDER BY document_name;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Find the name of the document that has been accessed the greatest number of times, as well as the count of how many times it has been accessed? [/INST]

Output: SELECT document_name ,  access_count FROM documents ORDER BY access_count DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What is the name of the document which has been accessed the most times, as well as the number of times it has been accessed? [/INST]

Output: SELECT document_name ,  access_count FROM documents ORDER BY access_count DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Find the types of documents with more than 4 documents. [/INST]

Output: SELECT document_type_code FROM documents GROUP BY document_type_code HAVING count(*)  >  4;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What are the codes of types of documents of which there are for or more? [/INST]

Output: SELECT document_type_code FROM documents GROUP BY document_type_code HAVING count(*)  >  4;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Find the total access count of all documents in the most popular document type. [/INST]

Output: SELECT sum(access_count) FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What is the total access count of documents that are of the most common document type? [/INST]

Output: SELECT sum(access_count) FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What is the average access count of documents? [/INST]

Output: SELECT avg(access_count) FROM documents;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Find the average access count across all documents? [/INST]

Output: SELECT avg(access_count) FROM documents;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What is the structure of the document with the least number of accesses? [/INST]

Output: SELECT t2.document_structure_description FROM documents AS t1 JOIN document_structures AS t2 ON t1.document_structure_code  =  t2.document_structure_code GROUP BY t1.document_structure_code ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Return the structure description of the document that has been accessed the fewest number of times. [/INST]

Output: SELECT t2.document_structure_description FROM documents AS t1 JOIN document_structures AS t2 ON t1.document_structure_code  =  t2.document_structure_code GROUP BY t1.document_structure_code ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What is the type of the document named "David CV"? [/INST]

Output: SELECT document_type_code FROM documents WHERE document_name  =  "David CV";


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Return the type code of the document named "David CV". [/INST]

Output: SELECT document_type_code FROM documents WHERE document_name  =  "David CV";


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Find the list of documents that are both in the most three popular type and have the most three popular structure. [/INST]

Output: SELECT document_name FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 3 INTERSECT SELECT document_name FROM documents GROUP BY document_structure_code ORDER BY count(*) DESC LIMIT 3;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What are the names of documents that have both one of the three most common types and one of three most common structures? [/INST]

Output: SELECT document_name FROM documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 3 INTERSECT SELECT document_name FROM documents GROUP BY document_structure_code ORDER BY count(*) DESC LIMIT 3;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What document types do have more than 10000 total access number. [/INST]

Output: SELECT document_type_code FROM documents GROUP BY document_type_code HAVING sum(access_count)  >  10000;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Return the codes of the document types that do not have a total access count of over 10000. [/INST]

Output: SELECT document_type_code FROM documents GROUP BY document_type_code HAVING sum(access_count)  >  10000;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What are all the section titles of the document named "David CV"? [/INST]

Output: SELECT t2.section_title FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code  =  t2.document_code WHERE t1.document_name  =  "David CV";


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Give the section titles of the document with the name "David CV". [/INST]

Output: SELECT t2.section_title FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code  =  t2.document_code WHERE t1.document_name  =  "David CV";


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: Find all the name of documents without any sections. [/INST]

Output: SELECT document_name FROM documents WHERE document_code NOT IN (SELECT document_code FROM document_sections);


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What are the names of documents that do not have any sections? [/INST]

Output: SELECT document_name FROM documents WHERE document_code NOT IN (SELECT document_code FROM document_sections);


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: List all the username and passwords of users with the most popular role. [/INST]

Output: SELECT user_name ,  password FROM users GROUP BY role_code ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Roles :
role_code [ TEXT ] primary_key
role_description [ TEXT ]

Users :
user_id [ INT ] primary_key
role_code [ TEXT ] Users.role_code = Roles.role_code
user_name [ TEXT ]
user_login [ TEXT ]
password [ TEXT ]

Document_Structures :
document_structure_code [ TEXT ] primary_key
parent_document_structure_code [ TEXT ]
document_structure_description [ TEXT ]

Functional_Areas :
functional_area_code [ TEXT ] primary_key
parent_functional_area_code [ TEXT ]
functional_area_description [ TEXT ]

Images :
image_id [ INT ] primary_key
image_alt_text [ TEXT ]
image_name [ TEXT ]
image_url [ TEXT ]

Documents :
document_code [ TEXT ] primary_key
document_structure_code [ TEXT ] Documents.document_structure_code = Document_Structures.document_structure_code
document_type_code [ TEXT ]
access_count [ INT ]
document_name [ TEXT ]

Document_Functional_Areas :
document_code [ TEXT ] Document_Functional_Areas.document_code = Documents.document_code
functional_area_code [ TEXT ] Document_Functional_Areas.functional_area_code = Functional_Areas.functional_area_code

Document_Sections :
section_id [ INT ] primary_key
document_code [ TEXT ] Document_Sections.document_code = Documents.document_code
section_sequence [ INT ]
section_code [ TEXT ]
section_title [ TEXT ]

Document_Sections_Images :
section_id [ INT ] primary_key Document_Sections_Images.section_id = Document_Sections.section_id
image_id [ INT ] Document_Sections_Images.image_id = Images.image_id

Please write me a SQL statement that answers the following question: What are the usernames and passwords of users that have the most common role? [/INST]

Output: SELECT user_name ,  password FROM users GROUP BY role_code ORDER BY count(*) DESC LIMIT 1;