Question: What are the distinct grant amount for the grants where the documents were sent before '1986-08-26 20:49:27' and grant were ended after '1989-03-16 18:27:16'?

Context: CREATE TABLE grants (grant_amount VARCHAR, grant_end_date INTEGER); CREATE TABLE Grants (grant_amount VARCHAR, grant_id VARCHAR); CREATE TABLE Documents (grant_id VARCHAR, sent_date INTEGER)

SELECT T1.grant_amount FROM Grants AS T1 JOIN Documents AS T2 ON T1.grant_id = T2.grant_id WHERE T2.sent_date < '1986-08-26 20:49:27' INTERSECT SELECT grant_amount FROM grants WHERE grant_end_date > '1989-03-16 18:27:16'


Question: List the project details of the project both producing patent and paper as outcomes.

Context: CREATE TABLE Project_outcomes (project_id VARCHAR, outcome_code VARCHAR); CREATE TABLE Projects (project_details VARCHAR, project_id VARCHAR)

SELECT T1.project_details FROM Projects AS T1 JOIN Project_outcomes AS T2 ON T1.project_id = T2.project_id WHERE T2.outcome_code = 'Paper' INTERSECT SELECT T1.project_details FROM Projects AS T1 JOIN Project_outcomes AS T2 ON T1.project_id = T2.project_id WHERE T2.outcome_code = 'Patent'


Question: What is the total grant amount of the organisations described as research?

Context: CREATE TABLE organisation_Types (organisation_type VARCHAR, organisation_type_description VARCHAR); CREATE TABLE Grants (organisation_id VARCHAR); CREATE TABLE Organisations (organisation_id VARCHAR, organisation_type VARCHAR)

SELECT SUM(grant_amount) FROM Grants AS T1 JOIN Organisations AS T2 ON T1.organisation_id = T2.organisation_id JOIN organisation_Types AS T3 ON T2.organisation_type = T3.organisation_type WHERE T3.organisation_type_description = 'Research'


Question: List from which date and to which date these staff work: project staff of the project which hires the most staffs

Context: CREATE TABLE Project_Staff (date_from VARCHAR, date_to VARCHAR, project_id VARCHAR, role_code VARCHAR)

SELECT date_from, date_to FROM Project_Staff WHERE project_id IN (SELECT project_id FROM Project_Staff GROUP BY project_id ORDER BY COUNT(*) DESC LIMIT 1) UNION SELECT date_from, date_to FROM Project_Staff WHERE role_code = 'leader'


Question: Find the organisation ids and details of the organisations which are involved in

Context: CREATE TABLE Grants (organisation_id VARCHAR, grant_amount INTEGER); CREATE TABLE Organisations (organisation_id VARCHAR, organisation_details VARCHAR)

SELECT T2.organisation_id, T2.organisation_details FROM Grants AS T1 JOIN Organisations AS T2 ON T1.organisation_id = T2.organisation_id GROUP BY T2.organisation_id HAVING SUM(T1.grant_amount) > 6000


Question: What is the organisation type and id of the organisation which has the most number of research staff?

Context: CREATE TABLE Research_Staff (employer_organisation_id VARCHAR); CREATE TABLE Organisations (organisation_type VARCHAR, organisation_id VARCHAR)

SELECT T1.organisation_type, T1.organisation_id FROM Organisations AS T1 JOIN Research_Staff AS T2 ON T1.organisation_id = T2.employer_organisation_id GROUP BY T1.organisation_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Which organisation type hires most research staff?

SELECT T1.organisation_type FROM Organisations AS T1 JOIN Research_Staff AS T2 ON T1.organisation_id = T2.employer_organisation_id GROUP BY T1.organisation_type ORDER BY COUNT(*) DESC LIMIT 1


Question: Find out the send dates of the documents with the grant amount of more than 5000 were granted by organisation type described

Context: CREATE TABLE organisation_Types (organisation_type VARCHAR, organisation_type_description VARCHAR); CREATE TABLE Grants (grant_id VARCHAR, organisation_id VARCHAR, grant_amount VARCHAR); CREATE TABLE Organisations (organisation_id VARCHAR, organisation_type VARCHAR); CREATE TABLE documents (sent_date VARCHAR, grant_id VARCHAR)

SELECT T1.sent_date FROM documents AS T1 JOIN Grants AS T2 ON T1.grant_id = T2.grant_id JOIN Organisations AS T3 ON T2.organisation_id = T3.organisation_id JOIN organisation_Types AS T4 ON T3.organisation_type = T4.organisation_type WHERE T2.grant_amount > 5000 AND T4.organisation_type_description = 'Research'


Question: What are the response received dates for the documents described as 'Regular' or granted with more than 100?

Context: CREATE TABLE Documents (response_received_date VARCHAR, document_type_code VARCHAR, grant_id VARCHAR); CREATE TABLE Document_Types (document_type_code VARCHAR, document_description VARCHAR); CREATE TABLE Grants (grant_id VARCHAR, grant_amount VARCHAR)

SELECT T1.response_received_date FROM Documents AS T1 JOIN Document_Types AS T2 ON T1.document_type_code = T2.document_type_code JOIN Grants AS T3 ON T1.grant_id = T3.grant_id WHERE T2.document_description = 'Regular' OR T3.grant_amount > 100


Question: List the project details of the projects which did not hire any staff for a researcher role.

Context: CREATE TABLE Projects (project_details VARCHAR, project_id VARCHAR, role_code VARCHAR); CREATE TABLE Project_Staff (project_details VARCHAR, project_id VARCHAR, role_code VARCHAR)

SELECT project_details FROM Projects WHERE NOT project_id IN (SELECT project_id FROM Project_Staff WHERE role_code = 'researcher')


Question: What are the task details, task id and project id for the projects which are detailed as 'omnis' or  have more than 2 outcomes?

Context: CREATE TABLE Projects (project_id VARCHAR, project_details VARCHAR); CREATE TABLE Project_outcomes (project_id VARCHAR); CREATE TABLE Tasks (task_details VARCHAR, task_id VARCHAR, project_id VARCHAR)

SELECT T1.task_details, T1.task_id, T2.project_id FROM Tasks AS T1 JOIN Projects AS T2 ON T1.project_id = T2.project_id WHERE T2.project_details = 'omnis' UNION SELECT T1.task_details, T1.task_id, T2.project_id FROM Tasks AS T1 JOIN Projects AS T2 ON T1.project_id = T2.project_id JOIN Project_outcomes AS T3 ON T2.project_id = T3.project_id GROUP BY T2.project_id HAVING COUNT(*) > 2


Question: When do all the researcher role staff start to work, and when do they stop working?

Context: CREATE TABLE Project_Staff (date_from VARCHAR, date_to VARCHAR, role_code VARCHAR)

SELECT date_from, date_to FROM Project_Staff WHERE role_code = 'researcher'


Question: How many kinds of roles are there for the staff?

Context: CREATE TABLE Project_Staff (role_code VARCHAR)

SELECT COUNT(DISTINCT role_code) FROM Project_Staff


Question: What is the total amount of grants given by each organisations? Also list the organisation id.

Context: CREATE TABLE Grants (organisation_id VARCHAR, grant_amount INTEGER)

SELECT SUM(grant_amount), organisation_id FROM Grants GROUP BY organisation_id


Question: List the project details of the projects with the research outcome described with the substring 'Published'.

Context: CREATE TABLE Research_outcomes (outcome_code VARCHAR, outcome_description VARCHAR); CREATE TABLE Project_outcomes (project_id VARCHAR, outcome_code VARCHAR); CREATE TABLE Projects (project_details VARCHAR, project_id VARCHAR)

SELECT T1.project_details FROM Projects AS T1 JOIN Project_outcomes AS T2 ON T1.project_id = T2.project_id JOIN Research_outcomes AS T3 ON T2.outcome_code = T3.outcome_code WHERE T3.outcome_description LIKE '%Published%'


Question: How many staff does each project has? List the project id and the number in an ascending order.

Context: CREATE TABLE Project_Staff (project_id VARCHAR); CREATE TABLE Projects (project_id VARCHAR)

SELECT T1.project_id, COUNT(*) FROM Project_Staff AS T1 JOIN Projects AS T2 ON T1.project_id = T2.project_id GROUP BY T1.project_id ORDER BY COUNT(*)


Question: What is the complete description of the researcher role.

Context: CREATE TABLE Staff_Roles (role_description VARCHAR, role_code VARCHAR)

SELECT role_description FROM Staff_Roles WHERE role_code = 'researcher'


Question: When did the first staff for the projects started working?

Context: CREATE TABLE Project_Staff (date_from VARCHAR)

SELECT date_from FROM Project_Staff ORDER BY date_from LIMIT 1


Question: Which project made the most number of outcomes? List the project details and the project id.

Context: CREATE TABLE Project_outcomes (project_id VARCHAR); CREATE TABLE Projects (project_details VARCHAR, project_id VARCHAR)

SELECT T1.project_details, T1.project_id FROM Projects AS T1 JOIN Project_outcomes AS T2 ON T1.project_id = T2.project_id GROUP BY T1.project_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Which projects have no outcome? List the project details.

Context: CREATE TABLE Project_outcomes (project_details VARCHAR, project_id VARCHAR); CREATE TABLE Projects (project_details VARCHAR, project_id VARCHAR)

SELECT project_details FROM Projects WHERE NOT project_id IN (SELECT project_id FROM Project_outcomes)


Question: Which organisation hired the most number of research staff? List the organisation id, type and detail.

Context: CREATE TABLE Organisations (organisation_id VARCHAR, organisation_type VARCHAR, organisation_details VARCHAR); CREATE TABLE Research_Staff (employer_organisation_id VARCHAR)

SELECT T1.organisation_id, T1.organisation_type, T1.organisation_details FROM Organisations AS T1 JOIN Research_Staff AS T2 ON T1.organisation_id = T2.employer_organisation_id GROUP BY T1.organisation_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Show the role description and the id of the project staff involved in most number of project outcomes?

Context: CREATE TABLE Project_outcomes (project_id VARCHAR); CREATE TABLE Project_Staff (staff_id VARCHAR, role_code VARCHAR, project_id VARCHAR); CREATE TABLE Staff_Roles (role_description VARCHAR, role_code VARCHAR)

SELECT T1.role_description, T2.staff_id FROM Staff_Roles AS T1 JOIN Project_Staff AS T2 ON T1.role_code = T2.role_code JOIN Project_outcomes AS T3 ON T2.project_id = T3.project_id GROUP BY T2.staff_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Which document type is described with the prefix 'Initial'?

Context: CREATE TABLE Document_Types (document_type_code VARCHAR, document_description VARCHAR)

SELECT document_type_code FROM Document_Types WHERE document_description LIKE 'Initial%'


Question: For grants with both documents described as 'Regular' and documents described as 'Initial Application', list its start date.

Context: CREATE TABLE Grants (grant_start_date VARCHAR, grant_id VARCHAR); CREATE TABLE Document_Types (document_type_code VARCHAR, document_description VARCHAR); CREATE TABLE Documents (grant_id VARCHAR, document_type_code VARCHAR)

SELECT T1.grant_start_date FROM Grants AS T1 JOIN Documents AS T2 ON T1.grant_id = T2.grant_id JOIN Document_Types AS T3 ON T2.document_type_code = T3.document_type_code WHERE T3.document_description = 'Regular' INTERSECT SELECT T1.grant_start_date FROM Grants AS T1 JOIN Documents AS T2 ON T1.grant_id = T2.grant_id JOIN Document_Types AS T3 ON T2.document_type_code = T3.document_type_code WHERE T3.document_description = 'Initial Application'


Question: How many documents can one grant have at most? List the grant id and number.

Context: CREATE TABLE Documents (grant_id VARCHAR)

SELECT grant_id, COUNT(*) FROM Documents GROUP BY grant_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Find the organisation type description of the organisation detailed as 'quo'.

Context: CREATE TABLE Organisations (organisation_type VARCHAR, organisation_details VARCHAR); CREATE TABLE organisation_Types (organisation_type_description VARCHAR, organisation_type VARCHAR)

SELECT T1.organisation_type_description FROM organisation_Types AS T1 JOIN Organisations AS T2 ON T1.organisation_type = T2.organisation_type WHERE T2.organisation_details = 'quo'


Question: What are all the details of the organisations described as 'Sponsor'? Sort the result in an ascending order.

Context: CREATE TABLE organisation_Types (organisation_type VARCHAR, organisation_type_description VARCHAR); CREATE TABLE Organisations (organisation_type VARCHAR)

SELECT organisation_details FROM Organisations AS T1 JOIN organisation_Types AS T2 ON T1.organisation_type = T2.organisation_type WHERE T2.organisation_type_description = 'Sponsor' ORDER BY organisation_details


Question: How many Patent outcomes are generated from all the projects?

Context: CREATE TABLE Project_outcomes (outcome_code VARCHAR)

SELECT COUNT(*) FROM Project_outcomes WHERE outcome_code = 'Patent'


Question: How many project staff worked as leaders or started working before '1989-04-24 23:51:54'?

Context: CREATE TABLE Project_Staff (role_code VARCHAR, date_from VARCHAR)

SELECT COUNT(*) FROM Project_Staff WHERE role_code = 'leader' OR date_from < '1989-04-24 23:51:54'


Question: What is the last date of the staff leaving the projects?

Context: CREATE TABLE Project_Staff (date_to VARCHAR)

SELECT date_to FROM Project_Staff ORDER BY date_to DESC LIMIT 1


Question: What are the result description of the project whose detail is 'sint'?

Context: CREATE TABLE Project_outcomes (outcome_code VARCHAR, project_id VARCHAR); CREATE TABLE Research_outcomes (outcome_description VARCHAR, outcome_code VARCHAR); CREATE TABLE Projects (project_id VARCHAR, project_details VARCHAR)

SELECT T1.outcome_description FROM Research_outcomes AS T1 JOIN Project_outcomes AS T2 ON T1.outcome_code = T2.outcome_code JOIN Projects AS T3 ON T2.project_id = T3.project_id WHERE T3.project_details = 'sint'


Question: List the organisation id with the maximum outcome count, and the count.

Context: CREATE TABLE Project_outcomes (project_id VARCHAR); CREATE TABLE Projects (organisation_id VARCHAR, project_id VARCHAR)

SELECT T1.organisation_id, COUNT(*) FROM Projects AS T1 JOIN Project_outcomes AS T2 ON T1.project_id = T2.project_id GROUP BY T1.organisation_id ORDER BY COUNT(*) DESC LIMIT 1


Question: List the project details of the projects launched by the organisation

Context: CREATE TABLE Projects (project_details VARCHAR, organisation_id VARCHAR)

SELECT project_details FROM Projects WHERE organisation_id IN (SELECT organisation_id FROM Projects GROUP BY organisation_id ORDER BY COUNT(*) DESC LIMIT 1)


Question: List the research staff details, and order in ascending order.

Context: CREATE TABLE Research_Staff (staff_details VARCHAR)

SELECT staff_details FROM Research_Staff ORDER BY staff_details


Question: How many tasks are there in total?

Context: CREATE TABLE Tasks (Id VARCHAR)


Question: How many tasks does each project have? List the task count and the project detail.

Context: CREATE TABLE Projects (project_details VARCHAR, project_id VARCHAR); CREATE TABLE Tasks (project_id VARCHAR)

SELECT COUNT(*), T1.project_details FROM Projects AS T1 JOIN Tasks AS T2 ON T1.project_id = T2.project_id GROUP BY T1.project_id


Question: What are the staff roles of the staff who

Context: CREATE TABLE Project_Staff (role_code VARCHAR, date_from VARCHAR, date_to VARCHAR)

SELECT role_code FROM Project_Staff WHERE date_from > '2003-04-19 15:06:20' AND date_to < '2016-03-15 00:33:18'


Question: What are the descriptions of all the project outcomes?

Context: CREATE TABLE Research_outcomes (outcome_description VARCHAR, outcome_code VARCHAR); CREATE TABLE Project_outcomes (outcome_code VARCHAR)

SELECT T1.outcome_description FROM Research_outcomes AS T1 JOIN Project_outcomes AS T2 ON T1.outcome_code = T2.outcome_code


Question: Which role is most common for the staff?

Context: CREATE TABLE Project_Staff (role_code VARCHAR)

SELECT role_code FROM Project_Staff GROUP BY role_code ORDER BY COUNT(*) DESC LIMIT 1


Question: How many friends does Dan have?

Context: CREATE TABLE PersonFriend (friend VARCHAR, name VARCHAR); CREATE TABLE Person (name VARCHAR)

SELECT COUNT(T2.friend) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T1.name = 'Dan'


Question: How many females does this network has?

Context: CREATE TABLE Person (gender VARCHAR)

SELECT COUNT(*) FROM Person WHERE gender = 'female'


Question: What is the average age for all person?

Context: CREATE TABLE Person (age INTEGER)


Question: How many different cities are they from?

Context: CREATE TABLE Person (city VARCHAR)


Question: How many type of jobs do they have?

Context: CREATE TABLE Person (job VARCHAR)


Question: Who is the oldest person?

Context: CREATE TABLE Person (name VARCHAR, age INTEGER); CREATE TABLE person (name VARCHAR, age INTEGER)

SELECT name FROM Person WHERE age = (SELECT MAX(age) FROM person)


Question: Who is the oldest person whose job is student?

Context: CREATE TABLE person (name VARCHAR, job VARCHAR, age INTEGER); CREATE TABLE Person (name VARCHAR, job VARCHAR, age INTEGER)

SELECT name FROM Person WHERE job = 'student' AND age = (SELECT MAX(age) FROM person WHERE job = 'student')


Question: Who is the youngest male?

Context: CREATE TABLE Person (name VARCHAR, gender VARCHAR, age INTEGER); CREATE TABLE person (name VARCHAR, gender VARCHAR, age INTEGER)

SELECT name FROM Person WHERE gender = 'male' AND age = (SELECT MIN(age) FROM person WHERE gender = 'male')


Question: How old is the doctor named Zach?

Context: CREATE TABLE Person (age VARCHAR, job VARCHAR, name VARCHAR)

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


Question: Who is the person whose age is below 30?

Context: CREATE TABLE Person (name VARCHAR, age INTEGER)


Question: How many people whose age is greater 30 and job is engineer?

Context: CREATE TABLE Person (age VARCHAR, job VARCHAR)

SELECT COUNT(*) FROM Person WHERE age > 30 AND job = 'engineer'


Question: What is the average age for each gender?

Context: CREATE TABLE Person (gender VARCHAR, age INTEGER)

SELECT AVG(age), gender FROM Person GROUP BY gender


Question: What is average age for different job title?

Context: CREATE TABLE Person (job VARCHAR, age INTEGER)

SELECT AVG(age), job FROM Person GROUP BY job


Question: What is average age of male for different job title?

Context: CREATE TABLE Person (job VARCHAR, age INTEGER, gender VARCHAR)

SELECT AVG(age), job FROM Person WHERE gender = 'male' GROUP BY job


Question: What is minimum age for different job title?

SELECT MIN(age), job FROM Person GROUP BY job


Question: Find the number of people who is under 40 for each gender.

SELECT COUNT(*), gender FROM Person WHERE age < 40 GROUP BY gender


Question: Find the name of people whose age is greater than any engineer sorted by their age.

Context: CREATE TABLE Person (name VARCHAR, age INTEGER, job VARCHAR); CREATE TABLE person (name VARCHAR, age INTEGER, job VARCHAR)

SELECT name FROM Person WHERE age > (SELECT MIN(age) FROM person WHERE job = 'engineer') ORDER BY age


Question: Find the number of people whose age is greater than all engineers.

Context: CREATE TABLE Person (age INTEGER, job VARCHAR); CREATE TABLE person (age INTEGER, job VARCHAR)

SELECT COUNT(*) FROM Person WHERE age > (SELECT MAX(age) FROM person WHERE job = 'engineer')


Question: list the name, job title of all people ordered by their names.

Context: CREATE TABLE Person (name VARCHAR, job VARCHAR)

SELECT name, job FROM Person ORDER BY name


Question: Find the names of all person sorted in the descending order using age.

Context: CREATE TABLE Person (name VARCHAR, age VARCHAR)

SELECT name FROM Person ORDER BY age DESC


Question: Find the name and age of all males in order of their age.

Context: CREATE TABLE Person (name VARCHAR, gender VARCHAR, age VARCHAR)

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


Question: Find the name and age of the person who is a friend of both Dan and Alice.

Context: CREATE TABLE Person (name VARCHAR, age VARCHAR); CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR)

SELECT T1.name, T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Dan' INTERSECT SELECT T1.name, T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Alice'


Question: Find the name and age of the person who is a friend of Dan or Alice.

SELECT DISTINCT T1.name, T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Dan' OR T2.friend = 'Alice'


Question: Find the name of the person who has friends with age above 40 and under age 30?

Context: CREATE TABLE Person (name VARCHAR, age INTEGER); CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR); CREATE TABLE Person (name VARCHAR)

SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age > 40) INTERSECT SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age < 30)


Question: Find the name of the person who has friends with age above 40 but not under age 30?

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)


Question: Find the name of the person who has no student friends.

Context: CREATE TABLE Person (name VARCHAR, job VARCHAR); CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR); CREATE TABLE person (name VARCHAR)

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'


Question: Find the person who has exactly one friend.

Context: CREATE TABLE PersonFriend (name VARCHAR)

SELECT name FROM PersonFriend GROUP BY name HAVING COUNT(*) = 1


Question: Who are the friends of Bob?

Context: CREATE TABLE PersonFriend (friend VARCHAR, name VARCHAR); CREATE TABLE Person (name VARCHAR)

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


Question: Find the name of persons who are friends with Bob.

Context: CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR); CREATE TABLE Person (name VARCHAR)

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


Question: Find the names of females who are friends with Zach

Context: CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR); CREATE TABLE Person (name VARCHAR, gender VARCHAR)

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


Question: Find the female friends of Alice.

Context: CREATE TABLE PersonFriend (friend VARCHAR, name VARCHAR); CREATE TABLE Person (name VARCHAR, gender VARCHAR)

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


Question: Find the male friend of Alice whose job is a doctor?

Context: CREATE TABLE PersonFriend (friend VARCHAR, name VARCHAR); CREATE TABLE Person (name VARCHAR, job VARCHAR, gender VARCHAR)

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'


Question: Who has a friend that is from new york city?

Context: CREATE TABLE Person (name VARCHAR, city VARCHAR); CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR)

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


Question: Who has friends that are younger than the average age?

Context: CREATE TABLE person (age INTEGER); CREATE TABLE Person (name VARCHAR, age INTEGER); CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR)

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)


Question: Who has friends that are older than the average age? Print their friends and their ages as well

Context: CREATE TABLE person (age INTEGER); CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR); CREATE TABLE Person (age INTEGER, name VARCHAR)

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)


Question: Who is the friend of Zach with longest year relationship?

Context: CREATE TABLE PersonFriend (friend VARCHAR, name VARCHAR, YEAR INTEGER)

SELECT friend FROM PersonFriend WHERE name = 'Zach' AND YEAR = (SELECT MAX(YEAR) FROM PersonFriend WHERE name = 'Zach')


Question: What is the age of the friend of Zach with longest year relationship?

Context: CREATE TABLE PersonFriend (friend VARCHAR, name VARCHAR, year VARCHAR); CREATE TABLE PersonFriend (YEAR INTEGER, name VARCHAR); CREATE TABLE Person (age VARCHAR, name VARCHAR)

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')


Question: Find the name of persons who are friends with Alice for the shortest years.

Context: CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR, YEAR INTEGER)

SELECT name FROM PersonFriend WHERE friend = 'Alice' AND YEAR = (SELECT MIN(YEAR) FROM PersonFriend WHERE friend = 'Alice')


Question: Find the name, age, and job title of persons who are friends with Alice for the longest years.

Context: CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR, year VARCHAR); CREATE TABLE Person (name VARCHAR, age VARCHAR, job VARCHAR); CREATE TABLE PersonFriend (YEAR INTEGER, friend VARCHAR)

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')


Question: Who is the person that has no friend?

Context: CREATE TABLE PersonFriend (name VARCHAR); CREATE TABLE person (name VARCHAR)

SELECT name FROM person EXCEPT SELECT name FROM PersonFriend


Question: Which person whose friends have the oldest average age?

Context: CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR); CREATE TABLE Person (age INTEGER, name VARCHAR)

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


Question: What is the total number of people who has no friend living in the city of Austin.

Context: CREATE TABLE person (name VARCHAR, friend VARCHAR, city VARCHAR); CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR, city VARCHAR)

SELECT COUNT(DISTINCT name) FROM PersonFriend WHERE NOT friend IN (SELECT name FROM person WHERE city = 'Austin')


Question: Find Alice's friends of friends.

Context: CREATE TABLE PersonFriend (name VARCHAR); CREATE TABLE PersonFriend (name VARCHAR, friend VARCHAR); CREATE TABLE Person (name VARCHAR)

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'


Question: How many members are there?

Context: CREATE TABLE member (Id VARCHAR)


Question: List the names of members in ascending alphabetical order.

Context: CREATE TABLE member (Name VARCHAR)


Question: What are the names and countries of members?

Context: CREATE TABLE member (Name VARCHAR, Country VARCHAR)


Question: Show the names of members whose country is "United States" or "Canada".

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


Question: Show the different countries and the number of members from each.

Context: CREATE TABLE member (Country VARCHAR)

SELECT Country, COUNT(*) FROM member GROUP BY Country


Question: Show the most common country across members.

Context: CREATE TABLE member (Country VARCHAR)

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


Question: Which countries have more than two members?

Context: CREATE TABLE member (Country VARCHAR)

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


Question: Show the leader names and locations of colleges.

Context: CREATE TABLE college (Leader_Name VARCHAR, College_Location VARCHAR)

SELECT Leader_Name, College_Location FROM college


Question: Show the names of members and names of colleges they go to.

Context: CREATE TABLE member (Name VARCHAR, College_ID VARCHAR); CREATE TABLE college (Name VARCHAR, College_ID VARCHAR)

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


Question: Show the names of members and the locations of colleges they go to in ascending alphabetical order of member names.

Context: CREATE TABLE member (Name VARCHAR, College_ID VARCHAR); CREATE TABLE college (College_Location VARCHAR, College_ID VARCHAR)

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


Question: Show the distinct leader names of colleges associated with members from country "Canada".

Context: CREATE TABLE college (Leader_Name VARCHAR, College_ID VARCHAR); CREATE TABLE member (College_ID VARCHAR, Country VARCHAR)

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


Question: Show the names of members and the decoration themes they have.

Context: CREATE TABLE member (Name VARCHAR, Member_ID VARCHAR); CREATE TABLE round (Decoration_Theme VARCHAR, Member_ID VARCHAR)

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


Question: Show the names of members that have a rank in round higher than 3.

Context: CREATE TABLE round (Member_ID VARCHAR, Rank_in_Round INTEGER); CREATE TABLE member (Name VARCHAR, Member_ID VARCHAR)

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


Question: Show the names of members in ascending order of their rank in rounds.

Context: CREATE TABLE member (Name VARCHAR, Member_ID VARCHAR); CREATE TABLE round (Member_ID VARCHAR)

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


Question: List the names of members who did not participate in any round.

Context: CREATE TABLE member (Name VARCHAR, Member_ID VARCHAR); CREATE TABLE round (Name VARCHAR, Member_ID VARCHAR)

SELECT Name FROM member WHERE NOT Member_ID IN (SELECT Member_ID FROM round)


Question: Find the name and access counts of all documents, in alphabetic order of the document name.

Context: CREATE TABLE documents (document_name VARCHAR, access_count VARCHAR)

SELECT document_name, access_count FROM documents ORDER BY document_name


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?

SELECT document_name, access_count FROM documents ORDER BY access_count DESC LIMIT 1


Question: Find the types of documents with more than 4 documents.

Context: CREATE TABLE documents (document_type_code VARCHAR)

SELECT document_type_code FROM documents GROUP BY document_type_code HAVING COUNT(*) > 4


Question: Find the total access count of all documents in the most popular document type.

Context: CREATE TABLE documents (access_count INTEGER, document_type_code VARCHAR)

SELECT SUM(access_count) FROM documents GROUP BY document_type_code ORDER BY COUNT(*) DESC LIMIT 1


Question: What is the average access count of documents?

Context: CREATE TABLE documents (access_count INTEGER)


Question: What is the structure of the document with the least number of accesses?

Context: CREATE TABLE document_structures (document_structure_description VARCHAR, document_structure_code VARCHAR); CREATE TABLE documents (document_structure_code VARCHAR)

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


Question: What is the type of the document named "David CV"?

Context: CREATE TABLE documents (document_type_code VARCHAR, document_name VARCHAR)

SELECT document_type_code FROM documents WHERE document_name = "David CV"


Question: Find the list of documents that are both in the most three popular type and have the most three popular structure.

Context: CREATE TABLE documents (document_name VARCHAR, document_type_code VARCHAR, document_structure_code VARCHAR)

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


Question: What document types do have more than 10000 total access number.

Context: CREATE TABLE documents (document_type_code VARCHAR, access_count INTEGER)

SELECT document_type_code FROM documents GROUP BY document_type_code HAVING SUM(access_count) > 10000


Question: What are all the section titles of the document named "David CV"?

Context: CREATE TABLE documents (document_code VARCHAR, document_name VARCHAR); CREATE TABLE document_sections (section_title VARCHAR, document_code VARCHAR)

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"


Question: Find all the name of documents without any sections.

Context: CREATE TABLE document_sections (document_name VARCHAR, document_code VARCHAR); CREATE TABLE documents (document_name VARCHAR, document_code VARCHAR)

SELECT document_name FROM documents WHERE NOT document_code IN (SELECT document_code FROM document_sections)


Question: List all the username and passwords of users with the most popular role.

Context: CREATE TABLE users (user_name VARCHAR, password VARCHAR, role_code VARCHAR)

SELECT user_name, password FROM users GROUP BY role_code ORDER BY COUNT(*) DESC LIMIT 1


Question: Find the average access counts of documents with functional area "Acknowledgement".

Context: CREATE TABLE document_functional_areas (document_code VARCHAR, functional_area_code VARCHAR); CREATE TABLE documents (access_count INTEGER, document_code VARCHAR); CREATE TABLE functional_areas (functional_area_code VARCHAR, functional_area_description VARCHAR)

SELECT AVG(t1.access_count) FROM documents AS t1 JOIN document_functional_areas AS t2 ON t1.document_code = t2.document_code JOIN functional_areas AS t3 ON t2.functional_area_code = t3.functional_area_code WHERE t3.functional_area_description = "Acknowledgement"


Question: Find names of the document without any images.

Context: CREATE TABLE document_sections_images (section_id VARCHAR); CREATE TABLE documents (document_name VARCHAR); CREATE TABLE documents (document_name VARCHAR, document_code VARCHAR); CREATE TABLE document_sections (document_code VARCHAR, section_id VARCHAR)

SELECT document_name FROM documents EXCEPT SELECT t1.document_name FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code = t2.document_code JOIN document_sections_images AS t3 ON t2.section_id = t3.section_id


Question: What is the name of the document with the most number of sections?

Context: CREATE TABLE document_sections (document_code VARCHAR); CREATE TABLE documents (document_name VARCHAR, document_code VARCHAR)

SELECT t1.document_name FROM documents AS t1 JOIN document_sections AS t2 ON t1.document_code = t2.document_code GROUP BY t1.document_code ORDER BY COUNT(*) DESC LIMIT 1


Question: List all the document names which contains "CV".

Context: CREATE TABLE documents (document_name VARCHAR)

SELECT document_name FROM documents WHERE document_name LIKE "%CV%"


Question: How many users are logged in?

Context: CREATE TABLE users (user_login VARCHAR)

SELECT COUNT(*) FROM users WHERE user_login = 1


Question: Find the description of the most popular role among the users that have logged in.

Context: CREATE TABLE users (role_description VARCHAR, role_code VARCHAR, user_login VARCHAR); CREATE TABLE ROLES (role_description VARCHAR, role_code VARCHAR, user_login VARCHAR)

SELECT role_description FROM ROLES WHERE role_code = (SELECT role_code FROM users WHERE user_login = 1 GROUP BY role_code ORDER BY COUNT(*) DESC LIMIT 1)


Question: Find the average access count of documents with the least popular structure.

Context: CREATE TABLE documents (access_count INTEGER, document_structure_code VARCHAR)

SELECT AVG(access_count) FROM documents GROUP BY document_structure_code ORDER BY COUNT(*) LIMIT 1


Question: List all the image name and URLs in the order of their names.

Context: CREATE TABLE images (image_name VARCHAR, image_url VARCHAR)

SELECT image_name, image_url FROM images ORDER BY image_name


Question: Find the number of users in each role.

Context: CREATE TABLE users (role_code VARCHAR)

SELECT COUNT(*), role_code FROM users GROUP BY role_code


Question: What document types have more than 2 corresponding documents?

Context: CREATE TABLE documents (document_type_code VARCHAR)

SELECT document_type_code FROM documents GROUP BY document_type_code HAVING COUNT(*) > 2


Question: How many companies are there?

Context: CREATE TABLE Companies (Id VARCHAR)


Question: List the names of companies in descending order of market value.

Context: CREATE TABLE Companies (name VARCHAR, Market_Value_billion VARCHAR)

SELECT name FROM Companies ORDER BY Market_Value_billion DESC


Question: What are the names of companies whose headquarters are not "USA"?

Context: CREATE TABLE Companies (name VARCHAR, Headquarters VARCHAR)

SELECT name FROM Companies WHERE Headquarters <> 'USA'


Question: What are the name and assets of each company, sorted in ascending order of company name?

Context: CREATE TABLE Companies (name VARCHAR, Assets_billion VARCHAR)

SELECT name, Assets_billion FROM Companies ORDER BY name


Question: What are the average profits of companies?

Context: CREATE TABLE Companies (Profits_billion INTEGER)

SELECT AVG(Profits_billion) FROM Companies


Question: What are the maximum and minimum sales of the companies whose industries are not "Banking".

Context: CREATE TABLE Companies (Sales_billion INTEGER, Industry VARCHAR)

SELECT MAX(Sales_billion), MIN(Sales_billion) FROM Companies WHERE Industry <> "Banking"


Question: How many different industries are the companies in?

Context: CREATE TABLE Companies (Industry VARCHAR)

SELECT COUNT(DISTINCT Industry) FROM Companies


Question: List the names of buildings in descending order of building height.

Context: CREATE TABLE buildings (name VARCHAR, Height VARCHAR)

SELECT name FROM buildings ORDER BY Height DESC


Question: Find the stories of the building with the largest height.

Context: CREATE TABLE buildings (Stories VARCHAR, Height VARCHAR)

SELECT Stories FROM buildings ORDER BY Height DESC LIMIT 1


Question: List the name of a building along with the name of a company whose office is in the building.

Context: CREATE TABLE buildings (name VARCHAR, id VARCHAR); CREATE TABLE Office_locations (building_id VARCHAR, company_id VARCHAR); CREATE TABLE Companies (name VARCHAR, id VARCHAR)

SELECT T3.name, T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id


Question: Show the names of the buildings that have more than one company offices.

Context: CREATE TABLE buildings (name VARCHAR, id VARCHAR); CREATE TABLE Companies (id VARCHAR); CREATE TABLE Office_locations (building_id VARCHAR, company_id VARCHAR)

SELECT T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id GROUP BY T1.building_id HAVING COUNT(*) > 1


Question: Show the name of the building that has the most company offices.

SELECT T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id GROUP BY T1.building_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Please show the names of the buildings whose status is "on-hold", in ascending order of stories.

Context: CREATE TABLE buildings (name VARCHAR, Status VARCHAR, Stories VARCHAR)

SELECT name FROM buildings WHERE Status = "on-hold" ORDER BY Stories


Question: Please show each industry and the corresponding number of companies in that industry.

SELECT Industry, COUNT(*) FROM Companies GROUP BY Industry


Question: Please show the industries of companies in descending order of the number of companies.

SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC


Question: List the industry shared by the most companies.

SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC LIMIT 1


Question: List the names of buildings that have no company office.

Context: CREATE TABLE buildings (name VARCHAR, id VARCHAR, building_id VARCHAR); CREATE TABLE Office_locations (name VARCHAR, id VARCHAR, building_id VARCHAR)

SELECT name FROM buildings WHERE NOT id IN (SELECT building_id FROM Office_locations)


Question: Show the industries shared by companies whose headquarters are "USA" and companies whose headquarters are "China".

Context: CREATE TABLE Companies (Industry VARCHAR, Headquarters VARCHAR)

SELECT Industry FROM Companies WHERE Headquarters = "USA" INTERSECT SELECT Industry FROM Companies WHERE Headquarters = "China"


Question: Find the number of companies whose industry is "Banking" or "Conglomerate",

SELECT COUNT(*) FROM Companies WHERE Industry = "Banking" OR Industry = "Conglomerate"


Question: Show the headquarters shared by more than two companies.

Context: CREATE TABLE Companies (Headquarters VARCHAR)

SELECT Headquarters FROM Companies GROUP BY Headquarters HAVING COUNT(*) > 2


Question: How many products are there?

Context: CREATE TABLE Products (Id VARCHAR)


Question: List the name of products in ascending order of price.

Context: CREATE TABLE Products (Product_Name VARCHAR, Product_Price VARCHAR)

SELECT Product_Name FROM Products ORDER BY Product_Price


Question: What are the names and type codes of products?

Context: CREATE TABLE Products (Product_Name VARCHAR, Product_Type_Code VARCHAR)

SELECT Product_Name, Product_Type_Code FROM Products


Question: Show the prices of the products named "Dining" or "Trading Policy".

Context: CREATE TABLE Products (Product_Price VARCHAR, Product_Name VARCHAR)

SELECT Product_Price FROM Products WHERE Product_Name = "Dining" OR Product_Name = "Trading Policy"


Question: What is the average price for products?

Context: CREATE TABLE Products (Product_Price INTEGER)


Question: What is the name of the product with the highest price?

SELECT Product_Name FROM Products ORDER BY Product_Price DESC LIMIT 1


Question: Show different type codes of products and the number of products with each type code.

Context: CREATE TABLE Products (Product_Type_Code VARCHAR)

SELECT Product_Type_Code, COUNT(*) FROM Products GROUP BY Product_Type_Code


Question: Show the most common type code across products.

SELECT Product_Type_Code FROM Products GROUP BY Product_Type_Code ORDER BY COUNT(*) DESC LIMIT 1


Question: Show the product type codes that have at least two products.

SELECT Product_Type_Code FROM Products GROUP BY Product_Type_Code HAVING COUNT(*) >= 2


Question: Show the product type codes that have both products with price higher than 4500 and products with price lower than 3000.

Context: CREATE TABLE Products (Product_Type_Code VARCHAR, Product_Price INTEGER)

SELECT Product_Type_Code FROM Products WHERE Product_Price > 4500 INTERSECT SELECT Product_Type_Code FROM Products WHERE Product_Price < 3000


Question: Show the names of products and the number of events they are in.

Context: CREATE TABLE Products (Product_Name VARCHAR, Product_ID VARCHAR); CREATE TABLE Products_in_Events (Product_ID VARCHAR)

SELECT T1.Product_Name, COUNT(*) FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name


Question: Show the names of products and the number of events they are in, sorted by the number of events in descending order.

SELECT T1.Product_Name, COUNT(*) FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name ORDER BY COUNT(*) DESC


Question: Show the names of products that are in at least two events.

SELECT T1.Product_Name FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name HAVING COUNT(*) >= 2


Question: Show the names of products that are in at least two events in ascending alphabetical order of product name.

SELECT T1.Product_Name FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name HAVING COUNT(*) >= 2 ORDER BY T1.Product_Name


Question: List the names of products that are not in any event.

Context: CREATE TABLE Products (Product_Name VARCHAR, Product_ID VARCHAR); CREATE TABLE Products_in_Events (Product_Name VARCHAR, Product_ID VARCHAR)

SELECT Product_Name FROM Products WHERE NOT Product_ID IN (SELECT Product_ID FROM Products_in_Events)


Question: How many artworks are there?

Context: CREATE TABLE artwork (Id VARCHAR)


Question: List the name of artworks in ascending alphabetical order.

Context: CREATE TABLE artwork (Name VARCHAR)


Question: List the name of artworks whose type is not "Program Talent Show".

Context: CREATE TABLE artwork (Name VARCHAR, TYPE VARCHAR)

SELECT Name FROM artwork WHERE TYPE <> "Program Talent Show"


Question: What are the names and locations of festivals?

Context: CREATE TABLE festival_detail (Festival_Name VARCHAR, LOCATION VARCHAR)

SELECT Festival_Name, LOCATION FROM festival_detail


Question: What are the names of the chairs of festivals, sorted in ascending order of the year held?

Context: CREATE TABLE festival_detail (Chair_Name VARCHAR, YEAR VARCHAR)

SELECT Chair_Name FROM festival_detail ORDER BY YEAR


Question: What is the location of the festival with the largest number of audience?

Context: CREATE TABLE festival_detail (LOCATION VARCHAR, Num_of_Audience VARCHAR)

SELECT LOCATION FROM festival_detail ORDER BY Num_of_Audience DESC LIMIT 1


Question: What are the names of festivals held in year 2007?

Context: CREATE TABLE festival_detail (Festival_Name VARCHAR, YEAR VARCHAR)

SELECT Festival_Name FROM festival_detail WHERE YEAR = 2007


Question: What is the average number of audience for festivals?

Context: CREATE TABLE festival_detail (Num_of_Audience INTEGER)

SELECT AVG(Num_of_Audience) FROM festival_detail


Question: Show the names of the three most recent festivals.

SELECT Festival_Name FROM festival_detail ORDER BY YEAR DESC LIMIT 3


Question: For each nomination, show the name of the artwork and name of the festival where it is nominated.

Context: CREATE TABLE artwork (Name VARCHAR, Artwork_ID VARCHAR); CREATE TABLE nomination (Artwork_ID VARCHAR, Festival_ID VARCHAR); CREATE TABLE festival_detail (Festival_Name VARCHAR, Festival_ID VARCHAR)

SELECT T2.Name, T3.Festival_Name FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID


Question: Show distinct types of artworks that are nominated in festivals in 2007.

Context: CREATE TABLE nomination (Artwork_ID VARCHAR, Festival_ID VARCHAR); CREATE TABLE festival_detail (Festival_ID VARCHAR, Year VARCHAR); CREATE TABLE artwork (Type VARCHAR, Artwork_ID VARCHAR)

SELECT DISTINCT T2.Type FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID WHERE T3.Year = 2007


Question: Show the names of artworks in ascending order of the year they are nominated in.

Context: CREATE TABLE artwork (Name VARCHAR, Artwork_ID VARCHAR); CREATE TABLE nomination (Artwork_ID VARCHAR, Festival_ID VARCHAR); CREATE TABLE festival_detail (Festival_ID VARCHAR, Year VARCHAR)

SELECT T2.Name FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID ORDER BY T3.Year


Question: Show the names of festivals that have nominated artworks of type "Program Talent Show".

Context: CREATE TABLE nomination (Artwork_ID VARCHAR, Festival_ID VARCHAR); CREATE TABLE artwork (Artwork_ID VARCHAR, Type VARCHAR); CREATE TABLE festival_detail (Festival_Name VARCHAR, Festival_ID VARCHAR)

SELECT T3.Festival_Name FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID WHERE T2.Type = "Program Talent Show"


Question: Show the ids and names of festivals that have at least two nominations for artworks.

Context: CREATE TABLE nomination (Festival_ID VARCHAR, Artwork_ID VARCHAR); CREATE TABLE festival_detail (Festival_Name VARCHAR, Festival_ID VARCHAR); CREATE TABLE artwork (Artwork_ID VARCHAR)

SELECT T1.Festival_ID, T3.Festival_Name FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID GROUP BY T1.Festival_ID HAVING COUNT(*) >= 2


Question: Show the id, name of each festival and the number of artworks it has nominated.

SELECT T1.Festival_ID, T3.Festival_Name, COUNT(*) FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID GROUP BY T1.Festival_ID


Question: Please show different types of artworks with the corresponding number of artworks of each type.

Context: CREATE TABLE artwork (TYPE VARCHAR)

SELECT TYPE, COUNT(*) FROM artwork GROUP BY TYPE


Question: List the most common type of artworks.

Context: CREATE TABLE artwork (TYPE VARCHAR)

SELECT TYPE FROM artwork GROUP BY TYPE ORDER BY COUNT(*) DESC LIMIT 1


Question: List the year in which there are more than one festivals.

Context: CREATE TABLE festival_detail (YEAR VARCHAR)

SELECT YEAR FROM festival_detail GROUP BY YEAR HAVING COUNT(*) > 1


Question: List the name of artworks that are not nominated.

Context: CREATE TABLE nomination (Name VARCHAR, Artwork_ID VARCHAR); CREATE TABLE Artwork (Name VARCHAR, Artwork_ID VARCHAR)

SELECT Name FROM Artwork WHERE NOT Artwork_ID IN (SELECT Artwork_ID FROM nomination)


Question: Show the number of audience in year 2008 or 2010.

Context: CREATE TABLE festival_detail (Num_of_Audience VARCHAR, YEAR VARCHAR)

SELECT Num_of_Audience FROM festival_detail WHERE YEAR = 2008 OR YEAR = 2010


Question: What are the total number of the audiences who visited any of the festivals?

SELECT SUM(Num_of_Audience) FROM festival_detail


Question: In which year are there festivals both inside the 'United States' and outside the 'United States'?

Context: CREATE TABLE festival_detail (YEAR VARCHAR, LOCATION VARCHAR)

SELECT YEAR FROM festival_detail WHERE LOCATION = 'United States' INTERSECT SELECT YEAR FROM festival_detail WHERE LOCATION <> 'United States'


Question: How many premises are there?

Context: CREATE TABLE premises (Id VARCHAR)


Question: What are all the distinct premise types?

Context: CREATE TABLE premises (premises_type VARCHAR)

SELECT DISTINCT premises_type FROM premises


Question: Find the types and details for all premises and order by the premise type.

Context: CREATE TABLE premises (premises_type VARCHAR, premise_details VARCHAR)

SELECT premises_type, premise_details FROM premises ORDER BY premises_type


Question: Show each premise type and the number of premises in that type.

SELECT premises_type, COUNT(*) FROM premises GROUP BY premises_type


Question: Show all distinct product categories along with the number of mailshots in each category.

Context: CREATE TABLE mailshot_campaigns (product_category VARCHAR)

SELECT product_category, COUNT(*) FROM mailshot_campaigns GROUP BY product_category


Question: Show the name and phone of the customer without any mailshot.

Context: CREATE TABLE customers (customer_name VARCHAR, customer_phone VARCHAR, customer_id VARCHAR); CREATE TABLE mailshot_customers (customer_name VARCHAR, customer_phone VARCHAR, customer_id VARCHAR)

SELECT customer_name, customer_phone FROM customers WHERE NOT customer_id IN (SELECT customer_id FROM mailshot_customers)


Question: Show the name and phone for customers with a mailshot with outcome code 'No Response'.

Context: CREATE TABLE customers (customer_name VARCHAR, customer_phone VARCHAR, customer_id VARCHAR); CREATE TABLE mailshot_customers (customer_id VARCHAR, outcome_code VARCHAR)

SELECT T1.customer_name, T1.customer_phone FROM customers AS T1 JOIN mailshot_customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.outcome_code = 'No Response'


Question: Show the outcome code of mailshots along with the number of mailshots in each outcome code.

Context: CREATE TABLE mailshot_customers (outcome_code VARCHAR)

SELECT outcome_code, COUNT(*) FROM mailshot_customers GROUP BY outcome_code


Question: Show the names of customers who have at least 2 mailshots with outcome code 'Order'.

Context: CREATE TABLE customers (customer_name VARCHAR, customer_id VARCHAR); CREATE TABLE mailshot_customers (customer_id VARCHAR)

SELECT T2.customer_name FROM mailshot_customers AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id WHERE outcome_code = 'Order' GROUP BY T1.customer_id HAVING COUNT(*) >= 2


Question: Show the names of customers who have the most mailshots.

SELECT T2.customer_name FROM mailshot_customers AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY COUNT(*) DESC LIMIT 1


Question: What are the name and payment method of customers who have both mailshots in 'Order' outcome and mailshots in 'No Response' outcome.

Context: CREATE TABLE customers (customer_name VARCHAR, payment_method VARCHAR, customer_id VARCHAR); CREATE TABLE mailshot_customers (customer_id VARCHAR, outcome_code VARCHAR)

SELECT T2.customer_name, T2.payment_method FROM mailshot_customers AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id WHERE T1.outcome_code = 'Order' INTERSECT SELECT T2.customer_name, T2.payment_method FROM mailshot_customers AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id WHERE T1.outcome_code = 'No Response'


Question: Show the premise type and address type code for all customer addresses.

Context: CREATE TABLE premises (premises_type VARCHAR, premise_id VARCHAR); CREATE TABLE customer_addresses (address_type_code VARCHAR, premise_id VARCHAR)

SELECT T2.premises_type, T1.address_type_code FROM customer_addresses AS T1 JOIN premises AS T2 ON T1.premise_id = T2.premise_id


Question: What are the distinct address type codes for all customer addresses?

Context: CREATE TABLE customer_addresses (address_type_code VARCHAR)

SELECT DISTINCT address_type_code FROM customer_addresses


Question: Show the shipping charge and customer id for customer orders with order status Cancelled or Paid.

Context: CREATE TABLE customer_orders (order_shipping_charges VARCHAR, customer_id VARCHAR, order_status_code VARCHAR)

SELECT order_shipping_charges, customer_id FROM customer_orders WHERE order_status_code = 'Cancelled' OR order_status_code = 'Paid'


Question: Show the names of customers having an order with shipping method FedEx and order status Paid.

Context: CREATE TABLE customers (customer_name VARCHAR, customer_id VARCHAR); CREATE TABLE customer_orders (customer_id VARCHAR)

SELECT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE shipping_method_code = 'FedEx' AND order_status_code = 'Paid'


Question: How many courses are there in total?

Context: CREATE TABLE COURSE (Id VARCHAR)


Question: How many courses have more than 2 credits?

Context: CREATE TABLE COURSE (Credits INTEGER)

SELECT COUNT(*) FROM COURSE WHERE Credits > 2


Question: List all names of courses with 1 credit?

Context: CREATE TABLE COURSE (CName VARCHAR, Credits VARCHAR)

SELECT CName FROM COURSE WHERE Credits = 1


Question: Which courses are taught on days MTW?

Context: CREATE TABLE COURSE (CName VARCHAR, Days VARCHAR)

SELECT CName FROM COURSE WHERE Days = "MTW"


Question: What is the number of departments in Division "AS"?

Context: CREATE TABLE DEPARTMENT (Division VARCHAR)

SELECT COUNT(*) FROM DEPARTMENT WHERE Division = "AS"


Question: What are the phones of departments in Room 268?

Context: CREATE TABLE DEPARTMENT (DPhone VARCHAR, Room VARCHAR)

SELECT DPhone FROM DEPARTMENT WHERE Room = 268


Question: Find the number of students that have at least one grade "B".

Context: CREATE TABLE ENROLLED_IN (StuID VARCHAR, Grade VARCHAR)

SELECT COUNT(DISTINCT StuID) FROM ENROLLED_IN WHERE Grade = "B"


Question: Find the max and min grade point for all letter grade.

Context: CREATE TABLE GRADECONVERSION (gradepoint INTEGER)

SELECT MAX(gradepoint), MIN(gradepoint) FROM GRADECONVERSION


Question: Find the first names of students whose first names contain letter "a".

Context: CREATE TABLE STUDENT (Fname VARCHAR)

SELECT DISTINCT Fname FROM STUDENT WHERE Fname LIKE '%a%'


Question: Find the first names and last names of male (sex is M) faculties who live in building NEB.

Context: CREATE TABLE FACULTY (Fname VARCHAR, Lname VARCHAR, sex VARCHAR, Building VARCHAR)

SELECT Fname, Lname FROM FACULTY WHERE sex = "M" AND Building = "NEB"


Question: Find the rooms of faculties with rank professor who live in building NEB.

Context: CREATE TABLE FACULTY (Room VARCHAR, Rank VARCHAR, Building VARCHAR)

SELECT Room FROM FACULTY WHERE Rank = "Professor" AND Building = "NEB"


Question: Find the department name that is in Building "Mergenthaler".

Context: CREATE TABLE DEPARTMENT (DName VARCHAR, Building VARCHAR)

SELECT DName FROM DEPARTMENT WHERE Building = "Mergenthaler"


Question: List all information about courses sorted by credits in the ascending order.

Context: CREATE TABLE COURSE (Credits VARCHAR)


Question: List the course name of courses sorted by credits.

SELECT CName FROM COURSE ORDER BY Credits


Question: Find the first name of students in the descending order of age.

Context: CREATE TABLE STUDENT (Fname VARCHAR, Age VARCHAR)

SELECT Fname FROM STUDENT ORDER BY Age DESC


Question: Find the last name of female (sex is F) students in the descending order of age.

Context: CREATE TABLE STUDENT (LName VARCHAR, Sex VARCHAR, Age VARCHAR)

SELECT LName FROM STUDENT WHERE Sex = "F" ORDER BY Age DESC


Question: Find the last names of faculties in building Barton in alphabetic order.

Context: CREATE TABLE FACULTY (Lname VARCHAR, Building VARCHAR)

SELECT Lname FROM FACULTY WHERE Building = "Barton" ORDER BY Lname


Question: Find the first names of faculties of rank Professor in alphabetic order.

Context: CREATE TABLE FACULTY (Fname VARCHAR, Rank VARCHAR)

SELECT Fname FROM FACULTY WHERE Rank = "Professor" ORDER BY Fname


Question: Find the name of the department that has the biggest number of students minored in?

Context: CREATE TABLE DEPARTMENT (DName VARCHAR, DNO VARCHAR); CREATE TABLE MINOR_IN (DNO VARCHAR)

SELECT T1.DName FROM DEPARTMENT AS T1 JOIN MINOR_IN AS T2 ON T1.DNO = T2.DNO GROUP BY T2.DNO ORDER BY COUNT(*) DESC LIMIT 1


Question: Find the name of the department that has no students minored in?

Context: CREATE TABLE DEPARTMENT (DName VARCHAR, DNO VARCHAR); CREATE TABLE MINOR_IN (DNO VARCHAR); CREATE TABLE DEPARTMENT (DName VARCHAR)

SELECT DName FROM DEPARTMENT EXCEPT SELECT T1.DName FROM DEPARTMENT AS T1 JOIN MINOR_IN AS T2 ON T1.DNO = T2.DNO


Question: Find the name of the department that has the fewest members.

Context: CREATE TABLE MEMBER_OF (DNO VARCHAR); CREATE TABLE DEPARTMENT (DName VARCHAR, DNO VARCHAR)

SELECT T1.DName FROM DEPARTMENT AS T1 JOIN MEMBER_OF AS T2 ON T1.DNO = T2.DNO GROUP BY T2.DNO ORDER BY COUNT(*) LIMIT 1


Question: Find the rank of the faculty that the fewest faculties belong to.

Context: CREATE TABLE FACULTY (Rank VARCHAR)

SELECT Rank FROM FACULTY GROUP BY Rank ORDER BY COUNT(*) LIMIT 1


Question: What are the first and last names of the instructors who teach the top 3 number of courses?

Context: CREATE TABLE COURSE (Instructor VARCHAR); CREATE TABLE FACULTY (Fname VARCHAR, Lname VARCHAR, FacID VARCHAR)

SELECT T2.Fname, T2.Lname FROM COURSE AS T1 JOIN FACULTY AS T2 ON T1.Instructor = T2.FacID GROUP BY T1.Instructor ORDER BY COUNT(*) DESC LIMIT 3


Question: Which building does the instructor who teaches the most number of courses live in?

Context: CREATE TABLE COURSE (Instructor VARCHAR); CREATE TABLE FACULTY (Building VARCHAR, FacID VARCHAR)

SELECT T2.Building FROM COURSE AS T1 JOIN FACULTY AS T2 ON T1.Instructor = T2.FacID GROUP BY T1.Instructor ORDER BY COUNT(*) DESC LIMIT 1


Question: What are the name of courses that have at least five enrollments?

Context: CREATE TABLE ENROLLED_IN (CID VARCHAR); CREATE TABLE COURSE (CName VARCHAR, CID VARCHAR)

SELECT T1.CName FROM COURSE AS T1 JOIN ENROLLED_IN AS T2 ON T1.CID = T2.CID GROUP BY T2.CID HAVING COUNT(*) >= 5


Question: Find the first name and last name of the instructor of course that has course name

Context: CREATE TABLE FACULTY (Fname VARCHAR, Lname VARCHAR, FacID VARCHAR); CREATE TABLE COURSE (Instructor VARCHAR, CName VARCHAR)

SELECT T2.Fname, T2.Lname FROM COURSE AS T1 JOIN FACULTY AS T2 ON T1.Instructor = T2.FacID WHERE T1.CName = "COMPUTER LITERACY"


Question: Find the department name and room of the course INTRODUCTION TO COMPUTER SCIENCE.

Context: CREATE TABLE COURSE (DNO VARCHAR, CName VARCHAR); CREATE TABLE DEPARTMENT (Dname VARCHAR, Room VARCHAR, DNO VARCHAR)

SELECT T2.Dname, T2.Room FROM COURSE AS T1 JOIN DEPARTMENT AS T2 ON T1.DNO = T2.DNO WHERE T1.CName = "INTRODUCTION TO COMPUTER SCIENCE"


Question: Find the student first and last names and grade points of all enrollments.

Context: CREATE TABLE ENROLLED_IN (Grade VARCHAR, StuID VARCHAR); CREATE TABLE STUDENT (Fname VARCHAR, LName VARCHAR, StuID VARCHAR); CREATE TABLE GRADECONVERSION (gradepoint VARCHAR, lettergrade VARCHAR)

SELECT T3.Fname, T3.LName, T2.gradepoint FROM ENROLLED_IN AS T1 JOIN GRADECONVERSION AS T2 JOIN STUDENT AS T3 ON T1.Grade = T2.lettergrade AND T1.StuID = T3.StuID


Question: Find the distinct student first names of all students that have grade point at least 3.8 in one course.

Context: CREATE TABLE ENROLLED_IN (Grade VARCHAR, StuID VARCHAR); CREATE TABLE STUDENT (Fname VARCHAR, StuID VARCHAR); CREATE TABLE GRADECONVERSION (gradepoint VARCHAR, lettergrade VARCHAR)

SELECT DISTINCT T3.Fname FROM ENROLLED_IN AS T1 JOIN GRADECONVERSION AS T2 JOIN STUDENT AS T3 ON T1.Grade = T2.lettergrade AND T1.StuID = T3.StuID WHERE T2.gradepoint >= 3.8


Question: Find the full names of faculties who are members of department with department number 520.

Context: CREATE TABLE FACULTY (Fname VARCHAR, Lname VARCHAR, FacID VARCHAR); CREATE TABLE MEMBER_OF (FacID VARCHAR, DNO VARCHAR)

SELECT T1.Fname, T1.Lname FROM FACULTY AS T1 JOIN MEMBER_OF AS T2 ON T1.FacID = T2.FacID WHERE T2.DNO = 520


Question: What are the first names and last names of the students that minor in the department with DNO 140.

Context: CREATE TABLE STUDENT (Fname VARCHAR, Lname VARCHAR, StuID VARCHAR); CREATE TABLE MINOR_IN (StuID VARCHAR, DNO VARCHAR)

SELECT T2.Fname, T2.Lname FROM MINOR_IN AS T1 JOIN STUDENT AS T2 ON T1.StuID = T2.StuID WHERE T1.DNO = 140


Question: Find the last names of faculties who are members of computer science department.

Context: CREATE TABLE DEPARTMENT (DNO VARCHAR, DName VARCHAR); CREATE TABLE MEMBER_OF (DNO VARCHAR, FacID VARCHAR); CREATE TABLE FACULTY (Lname VARCHAR, FacID VARCHAR)

SELECT T2.Lname FROM DEPARTMENT AS T1 JOIN FACULTY AS T2 ON T1.DNO = T3.DNO JOIN MEMBER_OF AS T3 ON T2.FacID = T3.FacID WHERE T1.DName = "Computer Science"


Question: Find the average grade point of student whose last name is Smith.

Context: CREATE TABLE ENROLLED_IN (Grade VARCHAR, StuID VARCHAR); CREATE TABLE STUDENT (LName VARCHAR, StuID VARCHAR); CREATE TABLE GRADECONVERSION (gradepoint INTEGER, lettergrade VARCHAR)

SELECT AVG(T2.gradepoint) FROM ENROLLED_IN AS T1 JOIN GRADECONVERSION AS T2 JOIN STUDENT AS T3 ON T1.Grade = T2.lettergrade AND T1.StuID = T3.StuID WHERE T3.LName = "Smith"


Question: What is the maximum and minimum grade point of students who live in NYC?

Context: CREATE TABLE ENROLLED_IN (Grade VARCHAR, StuID VARCHAR); CREATE TABLE STUDENT (city_code VARCHAR, StuID VARCHAR); CREATE TABLE GRADECONVERSION (gradepoint INTEGER, lettergrade VARCHAR)

SELECT MAX(T2.gradepoint), MIN(T2.gradepoint) FROM ENROLLED_IN AS T1 JOIN GRADECONVERSION AS T2 JOIN STUDENT AS T3 ON T1.Grade = T2.lettergrade AND T1.StuID = T3.StuID WHERE T3.city_code = "NYC"


Question: Find the names of courses that have either 3 credits or 1 credit but 4 hours.

Context: CREATE TABLE COURSE (CName VARCHAR, Credits VARCHAR, Hours VARCHAR)

SELECT CName FROM COURSE WHERE Credits = 3 UNION SELECT CName FROM COURSE WHERE Credits = 1 AND Hours = 4


Question: Find the names of departments that are either in division AS or in division EN and in Building NEB.

Context: CREATE TABLE DEPARTMENT (DName VARCHAR, Division VARCHAR, Building VARCHAR)

SELECT DName FROM DEPARTMENT WHERE Division = "AS" UNION SELECT DName FROM DEPARTMENT WHERE Division = "EN" AND Building = "NEB"


Question: Find the first name of students not enrolled in any course.

Context: CREATE TABLE STUDENT (Fname VARCHAR, StuID VARCHAR); CREATE TABLE ENROLLED_IN (Fname VARCHAR, StuID VARCHAR)

SELECT Fname FROM STUDENT WHERE NOT StuID IN (SELECT StuID FROM ENROLLED_IN)


Question: What are the ids of the top three products that were purchased in the largest amount?

Context: CREATE TABLE product_suppliers (product_id VARCHAR, total_amount_purchased VARCHAR)

SELECT product_id FROM product_suppliers ORDER BY total_amount_purchased DESC LIMIT 3


Question: What are the product id and product type of the cheapest product?

Context: CREATE TABLE products (product_id VARCHAR, product_type_code VARCHAR, product_price VARCHAR)

SELECT product_id, product_type_code FROM products ORDER BY product_price LIMIT 1


Question: Find the number of different product types.

Context: CREATE TABLE products (product_type_code VARCHAR)

SELECT COUNT(DISTINCT product_type_code) FROM products


Question: Return the address of customer 10.

Context: CREATE TABLE customer_addresses (address_id VARCHAR, customer_id VARCHAR); CREATE TABLE addresses (address_details VARCHAR, address_id VARCHAR)

SELECT T1.address_details FROM addresses AS T1 JOIN customer_addresses AS T2 ON T1.address_id = T2.address_id WHERE T2.customer_id = 10


Question: What are the staff ids and genders of all staffs whose job title is Department Manager?

Context: CREATE TABLE staff_department_assignments (staff_id VARCHAR, job_title_code VARCHAR); CREATE TABLE staff (staff_id VARCHAR, staff_gender VARCHAR)

SELECT T1.staff_id, T1.staff_gender FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Department Manager"


Question: For each payment method, return how many customers use it.

Context: CREATE TABLE customers (payment_method_code VARCHAR)

SELECT payment_method_code, COUNT(*) FROM customers GROUP BY payment_method_code


Question: What is the id of the product that was ordered the most often?

Context: CREATE TABLE order_items (product_id VARCHAR)

SELECT product_id FROM order_items GROUP BY product_id ORDER BY COUNT(*) DESC LIMIT 1


Question: What are the name, phone number and email address of the customer who made the largest number of orders?

Context: CREATE TABLE customers (customer_name VARCHAR, customer_phone VARCHAR, customer_email VARCHAR, customer_id VARCHAR); CREATE TABLE customer_orders (customer_id VARCHAR)

SELECT T1.customer_name, T1.customer_phone, T1.customer_email FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T2.customer_id ORDER BY COUNT(*) DESC LIMIT 1


Question: What is the average price for each type of product?

Context: CREATE TABLE products (product_type_code VARCHAR, product_price INTEGER)

SELECT product_type_code, AVG(product_price) FROM products GROUP BY product_type_code


Question: How many department stores does the store chain South have?

Context: CREATE TABLE department_stores (dept_store_chain_id VARCHAR); CREATE TABLE department_store_chain (dept_store_chain_id VARCHAR, dept_store_chain_name VARCHAR)

SELECT COUNT(*) FROM department_stores AS T1 JOIN department_store_chain AS T2 ON T1.dept_store_chain_id = T2.dept_store_chain_id WHERE T2.dept_store_chain_name = "South"


Question: What is the name and job title of the staff who was assigned the latest?

Context: CREATE TABLE staff (staff_name VARCHAR, staff_id VARCHAR); CREATE TABLE staff_department_assignments (job_title_code VARCHAR, staff_id VARCHAR, date_assigned_to VARCHAR)

SELECT T1.staff_name, T2.job_title_code FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id ORDER BY T2.date_assigned_to DESC LIMIT 1


Question: Give me the product type, name and price for all the products supplied by supplier id 3.

Context: CREATE TABLE products (product_type_code VARCHAR, product_name VARCHAR, product_price VARCHAR, product_id VARCHAR); CREATE TABLE product_suppliers (product_id VARCHAR, supplier_id VARCHAR)

SELECT T2.product_type_code, T2.product_name, T2.product_price FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id = T2.product_id WHERE T1.supplier_id = 3


Question: Return the distinct name of customers whose order status is Pending, in the order of customer id.

Context: CREATE TABLE customers (customer_name VARCHAR, customer_id VARCHAR); CREATE TABLE customer_orders (customer_id VARCHAR, order_status_code VARCHAR)

SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending" ORDER BY T2.customer_id


Question: Find the name and address of the customers who have both New and Pending orders.

Context: CREATE TABLE customers (customer_name VARCHAR, customer_address VARCHAR, customer_id VARCHAR); CREATE TABLE customer_orders (customer_id VARCHAR, order_status_code VARCHAR)

SELECT T1.customer_name, T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "New" INTERSECT SELECT T1.customer_name, T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending"


Question: Return ids of all the products that are supplied by supplier id 2 and are more expensive than the average price of all products.

Context: CREATE TABLE products (product_id VARCHAR, product_price INTEGER); CREATE TABLE product_suppliers (product_id VARCHAR, supplier_id VARCHAR); CREATE TABLE products (product_price INTEGER)

SELECT T1.product_id FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id = T2.product_id WHERE T1.supplier_id = 2 AND T2.product_price > (SELECT AVG(product_price) FROM products)


Question: What is the id and name of the department store that has both marketing and managing department?

Context: CREATE TABLE department_stores (dept_store_id VARCHAR, store_name VARCHAR); CREATE TABLE departments (dept_store_id VARCHAR, department_name VARCHAR)

SELECT T2.dept_store_id, T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "marketing" INTERSECT SELECT T2.dept_store_id, T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "managing"


Question: What are the ids of the two department store chains with the largest number of department stores?

Context: CREATE TABLE department_stores (dept_store_chain_id VARCHAR)

SELECT dept_store_chain_id FROM department_stores GROUP BY dept_store_chain_id ORDER BY COUNT(*) DESC LIMIT 2


Question: What is the id of the department with the least number of staff?

Context: CREATE TABLE staff_department_assignments (department_id VARCHAR)

SELECT department_id FROM staff_department_assignments GROUP BY department_id ORDER BY COUNT(*) LIMIT 1


Question: For each product type, return the maximum and minimum price.

SELECT product_type_code, MAX(product_price), MIN(product_price) FROM products GROUP BY product_type_code


Question: Find the product type whose average price is higher than the average price of all products.

SELECT product_type_code FROM products GROUP BY product_type_code HAVING AVG(product_price) > (SELECT AVG(product_price) FROM products)


Question: Find the id and name of the staff who has been assigned for the shortest period.

Context: CREATE TABLE Staff_Department_Assignments (staff_id VARCHAR); CREATE TABLE staff (staff_id VARCHAR, staff_name VARCHAR)

SELECT T1.staff_id, T1.staff_name FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id ORDER BY date_assigned_to - date_assigned_from LIMIT 1


Question: Return the names and ids of all products whose price is between 600 and 700.

Context: CREATE TABLE products (product_name VARCHAR, product_id VARCHAR, product_price INTEGER)

SELECT product_name, product_id FROM products WHERE product_price BETWEEN 600 AND 700


Question: Find the ids of all distinct customers who made order after some orders that were Cancelled.

Context: CREATE TABLE Customer_Orders (customer_id VARCHAR, order_date INTEGER, order_status_code VARCHAR)

SELECT DISTINCT customer_id FROM Customer_Orders WHERE order_date > (SELECT MIN(order_date) FROM Customer_Orders WHERE order_status_code = "Cancelled")


Question: What is id of the staff who had a Staff Department Assignment earlier than any Clerical Staff?

Context: CREATE TABLE Staff_Department_Assignments (staff_id VARCHAR, date_assigned_to INTEGER, job_title_code VARCHAR)

SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to < (SELECT MAX(date_assigned_to) FROM Staff_Department_Assignments WHERE job_title_code = 'Clerical Staff')


Question: What are the names and ids of customers whose address contains TN?

Context: CREATE TABLE customers (customer_name VARCHAR, customer_id VARCHAR, customer_address VARCHAR)

SELECT customer_name, customer_id FROM customers WHERE customer_address LIKE "%TN%"


Question: Return the name and gender of the staff who was assigned in 2016.

Context: CREATE TABLE staff (staff_name VARCHAR, staff_gender VARCHAR, staff_id VARCHAR); CREATE TABLE staff_department_assignments (staff_id VARCHAR, date_assigned_from VARCHAR)

SELECT T1.staff_name, T1.staff_gender FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.date_assigned_from LIKE "2016%"


Question: List the name of staff who has been assigned multiple jobs.

Context: CREATE TABLE staff (staff_name VARCHAR, staff_id VARCHAR); CREATE TABLE staff_department_assignments (staff_id VARCHAR)

SELECT T1.staff_name FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id GROUP BY T2.staff_id HAVING COUNT(*) > 1


Question: List the name and phone number of all suppliers in the alphabetical order of their addresses.

Context: CREATE TABLE addresses (address_id VARCHAR, address_details VARCHAR); CREATE TABLE supplier_addresses (supplier_id VARCHAR, address_id VARCHAR); CREATE TABLE Suppliers (supplier_name VARCHAR, supplier_phone VARCHAR, supplier_id VARCHAR)

SELECT T1.supplier_name, T1.supplier_phone FROM Suppliers AS T1 JOIN supplier_addresses AS T2 ON T1.supplier_id = T2.supplier_id JOIN addresses AS T3 ON T2.address_id = T3.address_id ORDER BY T3.address_details


Question: What are the phone numbers of all customers and suppliers.

Context: CREATE TABLE suppliers (customer_phone VARCHAR, supplier_phone VARCHAR); CREATE TABLE customers (customer_phone VARCHAR, supplier_phone VARCHAR)

SELECT customer_phone FROM customers UNION SELECT supplier_phone FROM suppliers


Question: Return the ids of all products that were ordered more than three times or supplied more than 80000.

Context: CREATE TABLE Order_Items (product_id VARCHAR, total_amount_purchased INTEGER); CREATE TABLE Product_Suppliers (product_id VARCHAR, total_amount_purchased INTEGER)

SELECT product_id FROM Order_Items GROUP BY product_id HAVING COUNT(*) > 3 UNION SELECT product_id FROM Product_Suppliers GROUP BY product_id HAVING SUM(total_amount_purchased) > 80000


Question: What are id and name of the products whose price is lower than 600 or higher than 900?

Context: CREATE TABLE products (product_id VARCHAR, product_name VARCHAR, product_price VARCHAR)

SELECT product_id, product_name FROM products WHERE product_price < 600 OR product_price > 900


Question: Find the id of suppliers whose average amount purchased for each product is above 50000 or below 30000.

Context: CREATE TABLE Product_Suppliers (supplier_id VARCHAR, total_amount_purchased INTEGER)

SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id HAVING AVG(total_amount_purchased) > 50000 OR AVG(total_amount_purchased) < 30000


Question: What are the average amount purchased and value purchased for the supplier who supplies the most products.

Context: CREATE TABLE Product_Suppliers (total_amount_purchased INTEGER, total_value_purchased INTEGER, supplier_id VARCHAR)

SELECT AVG(total_amount_purchased), AVG(total_value_purchased) FROM Product_Suppliers WHERE supplier_id = (SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id ORDER BY COUNT(*) DESC LIMIT 1)


Question: What is the largest and smallest customer codes?

Context: CREATE TABLE Customers (customer_code INTEGER)

SELECT MAX(customer_code), MIN(customer_code) FROM Customers


Question: List the names of all the distinct customers who bought a keyboard.

Context: CREATE TABLE order_items (order_id VARCHAR, product_id VARCHAR); CREATE TABLE customers (customer_name VARCHAR, customer_id VARCHAR); CREATE TABLE products (product_id VARCHAR, product_name VARCHAR); CREATE TABLE customer_orders (customer_id VARCHAR, order_id VARCHAR)

SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id JOIN order_items AS T3 ON T2.order_id = T3.order_id JOIN products AS T4 ON T3.product_id = T4.product_id WHERE T4.product_name = "keyboard"


Question: List the names and phone numbers of all the distinct suppliers who supply red jeans.

Context: CREATE TABLE product_suppliers (supplier_id VARCHAR, product_id VARCHAR); CREATE TABLE suppliers (supplier_name VARCHAR, supplier_phone VARCHAR, supplier_id VARCHAR); CREATE TABLE products (product_id VARCHAR, product_name VARCHAR)

SELECT DISTINCT T1.supplier_name, T1.supplier_phone FROM suppliers AS T1 JOIN product_suppliers AS T2 ON T1.supplier_id = T2.supplier_id JOIN products AS T3 ON T2.product_id = T3.product_id WHERE T3.product_name = "red jeans"


Question: What are the highest and lowest prices of products, grouped by and alphabetically ordered by product type?

Context: CREATE TABLE products (product_type_code VARCHAR, product_price INTEGER)

SELECT MAX(product_price), MIN(product_price), product_type_code FROM products GROUP BY product_type_code ORDER BY product_type_code


Question: List the order id, customer id for orders in Cancelled status, ordered by their order dates.

Context: CREATE TABLE customer_orders (order_id VARCHAR, customer_id VARCHAR, order_status_code VARCHAR, order_date VARCHAR)

SELECT order_id, customer_id FROM customer_orders WHERE order_status_code = "Cancelled" ORDER BY order_date


Question: Find the names of products that were bought by at least two distinct customers.

Context: CREATE TABLE products (product_name VARCHAR, product_id VARCHAR); CREATE TABLE customer_orders (order_id VARCHAR, customer_id VARCHAR); CREATE TABLE order_items (order_id VARCHAR, product_id VARCHAR)

SELECT DISTINCT T3.product_name FROM customer_orders AS T1 JOIN order_items AS T2 ON T1.order_id = T2.order_id JOIN products AS T3 ON T2.product_id = T3.product_id GROUP BY T3.product_id HAVING COUNT(DISTINCT T1.customer_id) >= 2


Question: Find the names of customers who have bought by at least three distinct products.

Context: CREATE TABLE order_items (order_id VARCHAR, product_id VARCHAR); CREATE TABLE customers (customer_name VARCHAR, customer_id VARCHAR); CREATE TABLE customer_orders (customer_id VARCHAR, order_id VARCHAR)

SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id JOIN order_items AS T3 ON T2.order_id = T3.order_id GROUP BY T1.customer_id HAVING COUNT(DISTINCT T3.product_id) >= 3


Question: Find the name and gender of the staff who has been assigned the job of Sales Person but never Clerical Staff.

Context: CREATE TABLE staff (staff_name VARCHAR, staff_gender VARCHAR, staff_id VARCHAR); CREATE TABLE Staff_Department_Assignments (staff_id VARCHAR, job_title_code VARCHAR)

SELECT T1.staff_name, T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Sales Person" EXCEPT SELECT T1.staff_name, T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Clerical Staff"


Question: Find the id and name of customers whose address contains WY state and do not use credit card for payment.

Context: CREATE TABLE customers (customer_id VARCHAR, customer_name VARCHAR, customer_address VARCHAR, payment_method_code VARCHAR)

SELECT customer_id, customer_name FROM customers WHERE customer_address LIKE "%WY%" AND payment_method_code <> "Credit Card"


Question: Find the average price of all product clothes.

Context: CREATE TABLE products (product_price INTEGER, product_type_code VARCHAR)

SELECT AVG(product_price) FROM products WHERE product_type_code = 'Clothes'


Question: Find the name of the most expensive hardware product.

Context: CREATE TABLE products (product_name VARCHAR, product_type_code VARCHAR, product_price VARCHAR)

SELECT product_name FROM products WHERE product_type_code = 'Hardware' ORDER BY product_price DESC LIMIT 1


Question: How many aircrafts are there?

Context: CREATE TABLE aircraft (Id VARCHAR)


Question: List the description of all aircrafts.

Context: CREATE TABLE aircraft (Description VARCHAR)


Question: What is the average number of international passengers of all airports?

Context: CREATE TABLE airport (International_Passengers INTEGER)

SELECT AVG(International_Passengers) FROM airport


Question: What are the number of international and domestic passengers of the airport named London "Heathrow"?

Context: CREATE TABLE airport (International_Passengers VARCHAR, Domestic_Passengers VARCHAR, Airport_Name VARCHAR)

SELECT International_Passengers, Domestic_Passengers FROM airport WHERE Airport_Name = "London Heathrow"


Question: What are the total number of Domestic Passengers of airports that contain the word "London".

Context: CREATE TABLE airport (Domestic_Passengers INTEGER, Airport_Name VARCHAR)

SELECT SUM(Domestic_Passengers) FROM airport WHERE Airport_Name LIKE "%London%"


Question: What are the maximum and minimum number of transit passengers of all aiports.

Context: CREATE TABLE airport (Transit_Passengers INTEGER)

SELECT MAX(Transit_Passengers), MIN(Transit_Passengers) FROM airport


Question: What are the name of pilots aged 25 or older?

Context: CREATE TABLE pilot (Name VARCHAR, Age VARCHAR)


Question: List all pilot names in ascending alphabetical order.

Context: CREATE TABLE pilot (Name VARCHAR)


Question: List names of all pilot aged 30 or younger in descending alphabetical order.

SELECT Name FROM pilot WHERE Age <= 30 ORDER BY Name DESC


Question: Please show the names of aircrafts associated with airport with name "London Gatwick".

Context: CREATE TABLE airport (Airport_ID VARCHAR, Airport_Name VARCHAR); CREATE TABLE aircraft (Aircraft VARCHAR, Aircraft_ID VARCHAR); CREATE TABLE airport_aircraft (Aircraft_ID VARCHAR, Airport_ID VARCHAR)

SELECT T1.Aircraft FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Airport_Name = "London Gatwick"


Question: Please show the names and descriptions of aircrafts associated with airports that have a total number of passengers bigger than 10000000.

Context: CREATE TABLE airport (Airport_ID VARCHAR, Total_Passengers INTEGER); CREATE TABLE aircraft (Aircraft VARCHAR, Description VARCHAR, Aircraft_ID VARCHAR); CREATE TABLE airport_aircraft (Aircraft_ID VARCHAR, Airport_ID VARCHAR)

SELECT T1.Aircraft, T1.Description FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Total_Passengers > 10000000


Question: What is the average total number of passengers of airports that are associated with aircraft "Robinson R-22"?

Context: CREATE TABLE airport (Total_Passengers INTEGER, Airport_ID VARCHAR); CREATE TABLE aircraft (Aircraft_ID VARCHAR, Aircraft VARCHAR); CREATE TABLE airport_aircraft (Aircraft_ID VARCHAR, Airport_ID VARCHAR)

SELECT AVG(T3.Total_Passengers) FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T1.Aircraft = "Robinson R-22"


Question: Please list the location and the winning aircraft name.

Context: CREATE TABLE MATCH (Location VARCHAR, Winning_Aircraft VARCHAR); CREATE TABLE aircraft (Aircraft VARCHAR, Aircraft_ID VARCHAR)

SELECT T2.Location, T1.Aircraft FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft


Question: List the name of the aircraft that has been named winning aircraft the most number of times.

Context: CREATE TABLE MATCH (Winning_Aircraft VARCHAR); CREATE TABLE aircraft (Aircraft VARCHAR, Aircraft_ID VARCHAR)

SELECT T1.Aircraft FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft GROUP BY T2.Winning_Aircraft ORDER BY COUNT(*) DESC LIMIT 1


Question: List the names of aircrafts and the number of times it won matches.

SELECT T1.Aircraft, COUNT(*) FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft GROUP BY T2.Winning_Aircraft


Question: List names of all pilot in descending order of age.

SELECT Name FROM pilot ORDER BY Age DESC


Question: List the names of aircrafts and that won matches at least twice.

SELECT T1.Aircraft FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft GROUP BY T2.Winning_Aircraft HAVING COUNT(*) >= 2


Question: List the names of aircrafts and that did not win any match.

Context: CREATE TABLE aircraft (Aircraft VARCHAR, Aircraft_ID VARCHAR, Winning_Aircraft VARCHAR); CREATE TABLE MATCH (Aircraft VARCHAR, Aircraft_ID VARCHAR, Winning_Aircraft VARCHAR)

SELECT Aircraft FROM aircraft WHERE NOT Aircraft_ID IN (SELECT Winning_Aircraft FROM MATCH)


Question: Show the names of aircrafts that are associated with both an airport named "London Heathrow" and an airport named "London Gatwick"

SELECT T1.Aircraft FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Airport_Name = "London Heathrow" INTERSECT SELECT T1.Aircraft FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Airport_Name = "London Gatwick"


Question: Show all information on the airport that has the largest number of international passengers.

Context: CREATE TABLE airport (International_Passengers VARCHAR)

SELECT * FROM airport ORDER BY International_Passengers DESC LIMIT 1


Question: find the name and age of the pilot who has won the most number of times among the pilots who are younger than 30.

Context: CREATE TABLE MATCH (winning_pilot VARCHAR); CREATE TABLE pilot (name VARCHAR, age INTEGER, pilot_id VARCHAR)

SELECT t1.name, t1.age FROM pilot AS t1 JOIN MATCH AS t2 ON t1.pilot_id = t2.winning_pilot WHERE t1.age < 30 GROUP BY t2.winning_pilot ORDER BY COUNT(*) DESC LIMIT 1


Question: what is the name and age of the youngest winning pilot?

Context: CREATE TABLE pilot (name VARCHAR, age VARCHAR, pilot_id VARCHAR); CREATE TABLE MATCH (winning_pilot VARCHAR)

SELECT t1.name, t1.age FROM pilot AS t1 JOIN MATCH AS t2 ON t1.pilot_id = t2.winning_pilot ORDER BY t1.age LIMIT 1


Question: find the name of pilots who did not win the matches held in the country of Australia.

Context: CREATE TABLE MATCH (name VARCHAR, pilot_id VARCHAR, Winning_Pilot VARCHAR, country VARCHAR); CREATE TABLE pilot (name VARCHAR, pilot_id VARCHAR, Winning_Pilot VARCHAR, country VARCHAR)

SELECT name FROM pilot WHERE NOT pilot_id IN (SELECT Winning_Pilot FROM MATCH WHERE country = 'Australia')


Question: How many residents does each property have? List property id and resident count.

Context: CREATE TABLE properties (property_id VARCHAR); CREATE TABLE residents (property_id VARCHAR)

SELECT T1.property_id, COUNT(*) FROM properties AS T1 JOIN residents AS T2 ON T1.property_id = T2.property_id GROUP BY T1.property_id


Question: What is the distinct service types that are provided by the organization which has detail 'Denesik and Sons Party'?

Context: CREATE TABLE services (service_type_code VARCHAR, organization_id VARCHAR); CREATE TABLE organizations (organization_id VARCHAR, organization_details VARCHAR)

SELECT DISTINCT T1.service_type_code FROM services AS T1 JOIN organizations AS T2 ON T1.organization_id = T2.organization_id WHERE T2.organization_details = 'Denesik and Sons Party'


Question: How many services has each resident requested? List the resident id, details, and the count in descending order of the count.

Context: CREATE TABLE Residents_Services (resident_id VARCHAR); CREATE TABLE Residents (resident_id VARCHAR, other_details VARCHAR)

SELECT T1.resident_id, T1.other_details, COUNT(*) FROM Residents AS T1 JOIN Residents_Services AS T2 ON T1.resident_id = T2.resident_id GROUP BY T1.resident_id ORDER BY COUNT(*) DESC


Question: What is the maximum number that a certain service is provided? List the service id, details and number.

Context: CREATE TABLE Services (service_id VARCHAR, service_details VARCHAR); CREATE TABLE Residents_Services (service_id VARCHAR)

SELECT T1.service_id, T1.service_details, COUNT(*) FROM Services AS T1 JOIN Residents_Services AS T2 ON T1.service_id = T2.service_id GROUP BY T1.service_id ORDER BY COUNT(*) DESC LIMIT 1


Question: List the id and type of each thing, and the details of the organization that owns it.

Context: CREATE TABLE Organizations (organization_details VARCHAR, organization_id VARCHAR); CREATE TABLE Things (thing_id VARCHAR, type_of_Thing_Code VARCHAR, organization_id VARCHAR)

SELECT T1.thing_id, T1.type_of_Thing_Code, T2.organization_details FROM Things AS T1 JOIN Organizations AS T2 ON T1.organization_id = T2.organization_id


Question: What are the id and details of the customers who have at least 3 events?

Context: CREATE TABLE Customers (customer_id VARCHAR, customer_details VARCHAR); CREATE TABLE Customer_Events (customer_id VARCHAR)

SELECT T1.customer_id, T1.customer_details FROM Customers AS T1 JOIN Customer_Events AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id HAVING COUNT(*) >= 3


Question: What is each customer's move in date, and the corresponding customer id and details?

Context: CREATE TABLE Customer_Events (date_moved_in VARCHAR, customer_id VARCHAR); CREATE TABLE Customers (customer_id VARCHAR, customer_details VARCHAR)

SELECT T2.date_moved_in, T1.customer_id, T1.customer_details FROM Customers AS T1 JOIN Customer_Events AS T2 ON T1.customer_id = T2.customer_id


Question: Which events have the number of notes between one and three? List the event id and the property id.

Context: CREATE TABLE Customer_Events (Customer_Event_ID VARCHAR, property_id VARCHAR, customer_event_id VARCHAR); CREATE TABLE Customer_Event_Notes (Customer_Event_ID VARCHAR)

SELECT T1.Customer_Event_ID, T1.property_id FROM Customer_Events AS T1 JOIN Customer_Event_Notes AS T2 ON T1.Customer_Event_ID = T2.Customer_Event_ID GROUP BY T1.customer_event_id HAVING COUNT(*) BETWEEN 1 AND 3


Question: What are the distinct id and type of the thing that has the status 'Close' or has a status record before the date '2017-06-19 02:59:21'

Context: CREATE TABLE Timed_Status_of_Things (thing_id VARCHAR, Status_of_Thing_Code VARCHAR, Date_and_Date VARCHAR); CREATE TABLE Things (thing_id VARCHAR, Type_of_Thing_Code VARCHAR)

SELECT DISTINCT T2.thing_id, T2.Type_of_Thing_Code FROM Timed_Status_of_Things AS T1 JOIN Things AS T2 ON T1.thing_id = T2.thing_id WHERE T1.Status_of_Thing_Code = 'Close' OR T1.Date_and_Date < '2017-06-19 02:59:21'


Question: How many distinct locations have the things with service detail 'Unsatisfied' been located in?

Context: CREATE TABLE Timed_Locations_of_Things (Location_Code VARCHAR, thing_id VARCHAR); CREATE TABLE Things (thing_id VARCHAR, service_details VARCHAR)

SELECT COUNT(DISTINCT T2.Location_Code) FROM Things AS T1 JOIN Timed_Locations_of_Things AS T2 ON T1.thing_id = T2.thing_id WHERE T1.service_details = 'Unsatisfied'


Question: How many different status codes of things are there?

Context: CREATE TABLE Timed_Status_of_Things (Status_of_Thing_Code VARCHAR)

SELECT COUNT(DISTINCT Status_of_Thing_Code) FROM Timed_Status_of_Things


Question: Which organizations are not a parent organization of others? List the organization id.

Context: CREATE TABLE organizations (organization_id VARCHAR, parent_organization_id VARCHAR)

SELECT organization_id FROM organizations EXCEPT SELECT parent_organization_id FROM organizations


Question: When is the last day any resident moved in?

Context: CREATE TABLE Residents (date_moved_in INTEGER)

SELECT MAX(date_moved_in) FROM Residents


Question: What are the resident details containing the substring 'Miss'?

Context: CREATE TABLE Residents (other_details VARCHAR)

SELECT other_details FROM Residents WHERE other_details LIKE '%Miss%'


Question: List the customer event id and the corresponding move in date and property id.

Context: CREATE TABLE customer_events (customer_event_id VARCHAR, date_moved_in VARCHAR, property_id VARCHAR)

SELECT customer_event_id, date_moved_in, property_id FROM customer_events


Question: How many customers did not have any event?

Context: CREATE TABLE customers (customer_id VARCHAR); CREATE TABLE customer_events (customer_id VARCHAR)

SELECT COUNT(*) FROM customers WHERE NOT customer_id IN (SELECT customer_id FROM customer_events)


Question: What are the distinct move in dates of the residents?

Context: CREATE TABLE residents (date_moved_in VARCHAR)

SELECT DISTINCT date_moved_in FROM residents


Question: List the locations of schools in ascending order of enrollment.

Context: CREATE TABLE school (LOCATION VARCHAR, Enrollment VARCHAR)

SELECT LOCATION FROM school ORDER BY Enrollment


Question: List the locations of schools in descending order of founded year.

Context: CREATE TABLE school (LOCATION VARCHAR, Founded VARCHAR)

SELECT LOCATION FROM school ORDER BY Founded DESC


Question: What are the enrollments of schools whose denomination is not "Catholic"?

Context: CREATE TABLE school (Enrollment VARCHAR, Denomination VARCHAR)

SELECT Enrollment FROM school WHERE Denomination <> "Catholic"


Question: What is the average enrollment of schools?

Context: CREATE TABLE school (Enrollment INTEGER)


Question: What are the teams of the players, sorted in ascending alphabetical order?

Context: CREATE TABLE player (Team VARCHAR)


Question: Find the team of the player of the highest age.

Context: CREATE TABLE player (Team VARCHAR, Age VARCHAR)

SELECT Team FROM player ORDER BY Age DESC LIMIT 1


Question: List the teams of the players with the top 5 largest ages.

SELECT Team FROM player ORDER BY Age DESC LIMIT 5


Question: For each player, show the team and the location of school they belong to.

Context: CREATE TABLE school (Location VARCHAR, School_ID VARCHAR); CREATE TABLE player (Team VARCHAR, School_ID VARCHAR)

SELECT T1.Team, T2.Location FROM player AS T1 JOIN school AS T2 ON T1.School_ID = T2.School_ID


Question: Show the locations of schools that have more than 1 player.

Context: CREATE TABLE player (School_ID VARCHAR); CREATE TABLE school (Location VARCHAR, School_ID VARCHAR)

SELECT T2.Location FROM player AS T1 JOIN school AS T2 ON T1.School_ID = T2.School_ID GROUP BY T1.School_ID HAVING COUNT(*) > 1


Question: Show the denomination of the school that has the most players.

Context: CREATE TABLE player (School_ID VARCHAR); CREATE TABLE school (Denomination VARCHAR, School_ID VARCHAR)

SELECT T2.Denomination FROM player AS T1 JOIN school AS T2 ON T1.School_ID = T2.School_ID GROUP BY T1.School_ID ORDER BY COUNT(*) DESC LIMIT 1


Question: Show locations and nicknames of schools.

Context: CREATE TABLE school (Location VARCHAR, School_ID VARCHAR); CREATE TABLE school_details (Nickname VARCHAR, School_ID VARCHAR)

SELECT T1.Location, T2.Nickname FROM school AS T1 JOIN school_details AS T2 ON T1.School_ID = T2.School_ID


Question: Please show different denominations and the corresponding number of schools.

Context: CREATE TABLE school (Denomination VARCHAR)

SELECT Denomination, COUNT(*) FROM school GROUP BY Denomination


Question: Please show different denominations and the corresponding number of schools in descending order.

SELECT Denomination, COUNT(*) FROM school GROUP BY Denomination ORDER BY COUNT(*) DESC


Question: List the school color of the school that has the largest enrollment.

Context: CREATE TABLE school (School_Colors VARCHAR, Enrollment VARCHAR)

SELECT School_Colors FROM school ORDER BY Enrollment DESC LIMIT 1


Question: List the locations of schools that do not have any player.

Context: CREATE TABLE school (LOCATION VARCHAR, School_ID VARCHAR); CREATE TABLE Player (LOCATION VARCHAR, School_ID VARCHAR)

SELECT LOCATION FROM school WHERE NOT School_ID IN (SELECT School_ID FROM Player)


Question: Show the denomination shared by schools founded before 1890 and schools founded after 1900

Context: CREATE TABLE school (Denomination VARCHAR, Founded INTEGER)

SELECT Denomination FROM school WHERE Founded < 1890 INTERSECT SELECT Denomination FROM school WHERE Founded > 1900


Question: Show the nicknames of schools that are not in division 1.

Context: CREATE TABLE school_details (Nickname VARCHAR, Division VARCHAR)

SELECT Nickname FROM school_details WHERE Division <> "Division 1"


Question: Show the denomination shared by more than one school.

SELECT Denomination FROM school GROUP BY Denomination HAVING COUNT(*) > 1


Question: Find all the distinct district names ordered by city area in descending.

Context: CREATE TABLE district (District_name VARCHAR, city_area VARCHAR)

SELECT DISTINCT District_name FROM district ORDER BY city_area DESC


Question: Find the list of page size which have more than 3 product listed

Context: CREATE TABLE product (max_page_size VARCHAR)

SELECT max_page_size FROM product GROUP BY max_page_size HAVING COUNT(*) > 3


Question: Find the name and population of district with population between 200000 and 2000000

Context: CREATE TABLE district (District_name VARCHAR, City_Population INTEGER)

SELECT District_name, City_Population FROM district WHERE City_Population BETWEEN 200000 AND 2000000


Question: Find the name all districts with city area greater than 10 or population larger than 100000

Context: CREATE TABLE district (district_name VARCHAR, city_area VARCHAR, City_Population VARCHAR)

SELECT district_name FROM district WHERE city_area > 10 OR City_Population > 100000


Question: Which district has the largest population?

Context: CREATE TABLE district (district_name VARCHAR, city_population VARCHAR)

SELECT district_name FROM district ORDER BY city_population DESC LIMIT 1