Question: Find the number of rooms located on each block floor.

Context: CREATE TABLE room (blockfloor VARCHAR, blockcode VARCHAR); CREATE TABLE BLOCK (blockfloor VARCHAR, blockcode VARCHAR)

Answer: [SQL] SELECT COUNT(*), T1.blockfloor FROM BLOCK AS T1 JOIN room AS T2 ON T1.blockfloor = T2.blockfloor AND T1.blockcode = T2.blockcode GROUP BY T1.blockfloor [/SQL]


Question: Find the number of rooms for different block code?

Context: CREATE TABLE room (blockfloor VARCHAR, blockcode VARCHAR); CREATE TABLE BLOCK (blockcode VARCHAR, blockfloor VARCHAR)

Answer: [SQL] SELECT COUNT(*), T1.blockcode FROM BLOCK AS T1 JOIN room AS T2 ON T1.blockfloor = T2.blockfloor AND T1.blockcode = T2.blockcode GROUP BY T1.blockcode [/SQL]


Question: What are the unique block codes that have available rooms?

Context: CREATE TABLE room (blockcode VARCHAR, unavailable VARCHAR)

Answer: [SQL] SELECT DISTINCT blockcode FROM room WHERE unavailable = 0 [/SQL]


Question: How many different types of rooms are there?

Context: CREATE TABLE room (roomtype VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT roomtype) FROM room [/SQL]


Question: What is the names of the physicians who prescribe medication Thesisin?

Context: CREATE TABLE physician (name VARCHAR, employeeid VARCHAR); CREATE TABLE prescribes (physician VARCHAR, medication VARCHAR); CREATE TABLE medication (code VARCHAR, name VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.name FROM physician AS T1 JOIN prescribes AS T2 ON T1.employeeid = T2.physician JOIN medication AS T3 ON T3.code = T2.medication WHERE T3.name = "Thesisin" [/SQL]


Question: Find the name and position of physicians who prescribe some medication whose brand is X?

Context: CREATE TABLE medication (code VARCHAR, Brand VARCHAR); CREATE TABLE prescribes (physician VARCHAR, medication VARCHAR); CREATE TABLE physician (name VARCHAR, position VARCHAR, employeeid VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.name, T1.position FROM physician AS T1 JOIN prescribes AS T2 ON T1.employeeid = T2.physician JOIN medication AS T3 ON T3.code = T2.medication WHERE T3.Brand = "X" [/SQL]


Question: Find the number of medications prescribed for each brand.

Context: CREATE TABLE medication (name VARCHAR, brand VARCHAR, code VARCHAR); CREATE TABLE prescribes (medication VARCHAR)

Answer: [SQL] SELECT COUNT(*), T1.name FROM medication AS T1 JOIN prescribes AS T2 ON T1.code = T2.medication GROUP BY T1.brand [/SQL]


Question: Find the name of physicians whose position title contains the word 'senior'.

Context: CREATE TABLE physician (name VARCHAR, POSITION VARCHAR)

Answer: [SQL] SELECT name FROM physician WHERE POSITION LIKE '%senior%' [/SQL]


Question: Find the patient who has the most recent undergoing treatment?

Context: CREATE TABLE undergoes (patient VARCHAR, dateundergoes VARCHAR)

Answer: [SQL] SELECT patient FROM undergoes ORDER BY dateundergoes LIMIT 1 [/SQL]


Question: Find the names of all patients who have an undergoing treatment and are staying in room 111.

Context: CREATE TABLE undergoes (patient VARCHAR, Stay VARCHAR); CREATE TABLE stay (StayID VARCHAR, room VARCHAR); CREATE TABLE patient (name VARCHAR, SSN VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.name FROM undergoes AS T1 JOIN patient AS T2 ON T1.patient = T2.SSN JOIN stay AS T3 ON T1.Stay = T3.StayID WHERE T3.room = 111 [/SQL]


Question: List the names of all distinct nurses ordered by alphabetical order?

Context: CREATE TABLE nurse (name VARCHAR)

Answer: [SQL] SELECT DISTINCT name FROM nurse ORDER BY name [/SQL]


Question: Find the names of nurses who are nursing an undergoing treatment.

Context: CREATE TABLE undergoes (AssistingNurse VARCHAR); CREATE TABLE nurse (name VARCHAR, EmployeeID VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.name FROM undergoes AS T1 JOIN nurse AS T2 ON T1.AssistingNurse = T2.EmployeeID [/SQL]


Question: List the names of all distinct medications, ordered in an alphabetical order.

Context: CREATE TABLE medication (name VARCHAR)

Answer: [SQL] SELECT DISTINCT name FROM medication ORDER BY name [/SQL]


Question: What are the names of the physician who prescribed the highest dose?

Context: CREATE TABLE prescribes (physician VARCHAR, dose VARCHAR); CREATE TABLE physician (name VARCHAR, employeeid VARCHAR)

Answer: [SQL] SELECT T1.name FROM physician AS T1 JOIN prescribes AS T2 ON T1.employeeid = T2.physician ORDER BY T2.dose DESC LIMIT 1 [/SQL]


Question: List the physicians' employee ids together with their primary affiliation departments' ids.

Context: CREATE TABLE affiliated_with (physician VARCHAR, department VARCHAR, primaryaffiliation VARCHAR)

Answer: [SQL] SELECT physician, department FROM affiliated_with WHERE primaryaffiliation = 1 [/SQL]


Question: List the names of departments where some physicians are primarily affiliated with.

Context: CREATE TABLE affiliated_with (department VARCHAR); CREATE TABLE department (name VARCHAR, departmentid VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.name FROM affiliated_with AS T1 JOIN department AS T2 ON T1.department = T2.departmentid WHERE PrimaryAffiliation = 1 [/SQL]


Question: What nurses are on call with block floor 1 and block code 1? Tell me their names.

Context: CREATE TABLE on_call (nurse VARCHAR, blockfloor VARCHAR, blockcode VARCHAR)

Answer: [SQL] SELECT nurse FROM on_call WHERE blockfloor = 1 AND blockcode = 1 [/SQL]


Question: What are the highest cost, lowest cost and average cost of procedures?

Context: CREATE TABLE procedures (cost INTEGER)

Answer: [SQL] SELECT MAX(cost), MIN(cost), AVG(cost) FROM procedures [/SQL]


Question: List the name and cost of all procedures sorted by the cost from the highest to the lowest.

Context: CREATE TABLE procedures (name VARCHAR, cost VARCHAR)

Answer: [SQL] SELECT name, cost FROM procedures ORDER BY cost DESC [/SQL]


Question: Find the three most expensive procedures.

Answer: [SQL] SELECT name FROM procedures ORDER BY cost LIMIT 3 [/SQL]


Question: Find the physicians who are trained in a procedure that costs more than 5000.

Context: CREATE TABLE trained_in (physician VARCHAR, treatment VARCHAR); CREATE TABLE physician (name VARCHAR, employeeid VARCHAR); CREATE TABLE procedures (code VARCHAR, cost INTEGER)

Answer: [SQL] SELECT T1.name FROM physician AS T1 JOIN trained_in AS T2 ON T1.employeeid = T2.physician JOIN procedures AS T3 ON T3.code = T2.treatment WHERE T3.cost > 5000 [/SQL]


Question: Find the physician who was trained in the most expensive procedure?

Context: CREATE TABLE trained_in (physician VARCHAR, treatment VARCHAR); CREATE TABLE physician (name VARCHAR, employeeid VARCHAR); CREATE TABLE procedures (code VARCHAR, cost VARCHAR)

Answer: [SQL] SELECT T1.name FROM physician AS T1 JOIN trained_in AS T2 ON T1.employeeid = T2.physician JOIN procedures AS T3 ON T3.code = T2.treatment ORDER BY T3.cost DESC LIMIT 1 [/SQL]


Question: What is the average cost of procedures that physician John Wen was trained in?

Context: CREATE TABLE trained_in (physician VARCHAR, treatment VARCHAR); CREATE TABLE procedures (cost INTEGER, code VARCHAR); CREATE TABLE physician (employeeid VARCHAR, name VARCHAR)

Answer: [SQL] SELECT AVG(T3.cost) FROM physician AS T1 JOIN trained_in AS T2 ON T1.employeeid = T2.physician JOIN procedures AS T3 ON T3.code = T2.treatment WHERE T1.name = "John Wen" [/SQL]


Question: Find the names of procedures which physician John Wen was trained in.

Context: CREATE TABLE trained_in (physician VARCHAR, treatment VARCHAR); CREATE TABLE physician (employeeid VARCHAR, name VARCHAR); CREATE TABLE procedures (name VARCHAR, code VARCHAR)

Answer: [SQL] SELECT T3.name FROM physician AS T1 JOIN trained_in AS T2 ON T1.employeeid = T2.physician JOIN procedures AS T3 ON T3.code = T2.treatment WHERE T1.name = "John Wen" [/SQL]


Question: Find all procedures which cost more than 1000 or which physician John Wen was trained in.

Context: CREATE TABLE trained_in (physician VARCHAR, treatment VARCHAR); CREATE TABLE procedures (name VARCHAR, cost INTEGER); CREATE TABLE physician (employeeid VARCHAR, name VARCHAR); CREATE TABLE procedures (name VARCHAR, code VARCHAR)

Answer: [SQL] SELECT name FROM procedures WHERE cost > 1000 UNION SELECT T3.name FROM physician AS T1 JOIN trained_in AS T2 ON T1.employeeid = T2.physician JOIN procedures AS T3 ON T3.code = T2.treatment WHERE T1.name = "John Wen" [/SQL]


Question: Find the names of all procedures which cost more than 1000 but which physician John Wen was not trained in?

Answer: [SQL] SELECT name FROM procedures WHERE cost > 1000 EXCEPT SELECT T3.name FROM physician AS T1 JOIN trained_in AS T2 ON T1.employeeid = T2.physician JOIN procedures AS T3 ON T3.code = T2.treatment WHERE T1.name = "John Wen" [/SQL]


Question: Find the names of all procedures such that the cost is less than 5000 and physician John Wen was trained in.

Answer: [SQL] SELECT name FROM procedures WHERE cost < 5000 INTERSECT SELECT T3.name FROM physician AS T1 JOIN trained_in AS T2 ON T1.employeeid = T2.physician JOIN procedures AS T3 ON T3.code = T2.treatment WHERE T1.name = "John Wen" [/SQL]


Question: Find the name of physicians who are affiliated with both Surgery and Psychiatry departments.

Context: CREATE TABLE affiliated_with (physician VARCHAR, department VARCHAR); CREATE TABLE department (DepartmentID VARCHAR, name VARCHAR); CREATE TABLE physician (name VARCHAR, EmployeeID VARCHAR)

Answer: [SQL] SELECT T1.name FROM physician AS T1 JOIN affiliated_with AS T2 ON T1.EmployeeID = T2.physician JOIN department AS T3 ON T2.department = T3.DepartmentID WHERE T3.name = 'Surgery' INTERSECT SELECT T1.name FROM physician AS T1 JOIN affiliated_with AS T2 ON T1.EmployeeID = T2.physician JOIN department AS T3 ON T2.department = T3.DepartmentID WHERE T3.name = 'Psychiatry' [/SQL]


Question: Find the name of physicians who are affiliated with Surgery or Psychiatry department.

Answer: [SQL] SELECT T1.name FROM physician AS T1 JOIN affiliated_with AS T2 ON T1.EmployeeID = T2.physician JOIN department AS T3 ON T2.department = T3.DepartmentID WHERE T3.name = 'Surgery' OR T3.name = 'Psychiatry' [/SQL]


Question: Find the names of patients who are not using the medication of Procrastin-X.

Context: CREATE TABLE Prescribes (Patient VARCHAR, Medication VARCHAR); CREATE TABLE Medication (Code VARCHAR, name VARCHAR); CREATE TABLE patient (name VARCHAR, SSN VARCHAR); CREATE TABLE patient (name VARCHAR)

Answer: [SQL] SELECT name FROM patient EXCEPT SELECT T1.name FROM patient AS T1 JOIN Prescribes AS T2 ON T2.Patient = T1.SSN JOIN Medication AS T3 ON T2.Medication = T3.Code WHERE T3.name = 'Procrastin-X' [/SQL]


Question: Find the number of patients who are not using the medication of Procrastin-X.

Context: CREATE TABLE Prescribes (patient VARCHAR, Medication VARCHAR); CREATE TABLE patient (SSN VARCHAR); CREATE TABLE Medication (Code VARCHAR, name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM patient WHERE NOT SSN IN (SELECT T1.patient FROM Prescribes AS T1 JOIN Medication AS T2 ON T1.Medication = T2.Code WHERE T2.name = 'Procrastin-X') [/SQL]


Question: How many appointments are there?

Context: CREATE TABLE appointment (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM appointment [/SQL]


Question: Find the names of nurses who are on call.

Context: CREATE TABLE on_call (nurse VARCHAR); CREATE TABLE nurse (name VARCHAR, EmployeeID VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.name FROM nurse AS T1 JOIN on_call AS T2 ON T1.EmployeeID = T2.nurse [/SQL]


Question: How many ships are there?

Context: CREATE TABLE ship (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM ship [/SQL]


Question: List the name of ships in ascending order of tonnage.

Context: CREATE TABLE ship (Name VARCHAR, Tonnage VARCHAR)

Answer: [SQL] SELECT Name FROM ship ORDER BY Tonnage [/SQL]


Question: What are the type and nationality of ships?

Context: CREATE TABLE ship (TYPE VARCHAR, Nationality VARCHAR)

Answer: [SQL] SELECT TYPE, Nationality FROM ship [/SQL]


Question: List the name of ships whose nationality is not "United States".

Context: CREATE TABLE ship (Name VARCHAR, Nationality VARCHAR)

Answer: [SQL] SELECT Name FROM ship WHERE Nationality <> "United States" [/SQL]


Question: Show the name of ships whose nationality is either United States or United Kingdom.

Answer: [SQL] SELECT Name FROM ship WHERE Nationality = "United States" OR Nationality = "United Kingdom" [/SQL]


Question: What is the name of the ship with the largest tonnage?

Answer: [SQL] SELECT Name FROM ship ORDER BY Tonnage DESC LIMIT 1 [/SQL]


Question: Show different types of ships and the number of ships of each type.

Context: CREATE TABLE ship (TYPE VARCHAR)

Answer: [SQL] SELECT TYPE, COUNT(*) FROM ship GROUP BY TYPE [/SQL]


Question: Please show the most common type of ships.

Context: CREATE TABLE ship (TYPE VARCHAR)

Answer: [SQL] SELECT TYPE FROM ship GROUP BY TYPE ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: List the nations that have more than two ships.

Context: CREATE TABLE ship (Nationality VARCHAR)

Answer: [SQL] SELECT Nationality FROM ship GROUP BY Nationality HAVING COUNT(*) > 2 [/SQL]


Question: Show different types of ships and the average tonnage of ships of each type.

Context: CREATE TABLE ship (TYPE VARCHAR, Tonnage INTEGER)

Answer: [SQL] SELECT TYPE, AVG(Tonnage) FROM ship GROUP BY TYPE [/SQL]


Question: Show codes and fates of missions, and names of ships involved.

Context: CREATE TABLE mission (Code VARCHAR, Fate VARCHAR, Ship_ID VARCHAR); CREATE TABLE ship (Name VARCHAR, Ship_ID VARCHAR)

Answer: [SQL] SELECT T1.Code, T1.Fate, T2.Name FROM mission AS T1 JOIN ship AS T2 ON T1.Ship_ID = T2.Ship_ID [/SQL]


Question: Show names of ships involved in a mission launched after 1928.

Context: CREATE TABLE mission (Ship_ID VARCHAR, Launched_Year INTEGER); CREATE TABLE ship (Name VARCHAR, Ship_ID VARCHAR)

Answer: [SQL] SELECT T2.Name FROM mission AS T1 JOIN ship AS T2 ON T1.Ship_ID = T2.Ship_ID WHERE T1.Launched_Year > 1928 [/SQL]


Question: Show the distinct fate of missions that involve ships with nationality "United States"

Context: CREATE TABLE mission (Fate VARCHAR, Ship_ID VARCHAR); CREATE TABLE ship (Ship_ID VARCHAR, Nationality VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.Fate FROM mission AS T1 JOIN ship AS T2 ON T1.Ship_ID = T2.Ship_ID WHERE T2.Nationality = "United States" [/SQL]


Question: List the name of ships that are not involved in any mission

Context: CREATE TABLE mission (Name VARCHAR, Ship_ID VARCHAR); CREATE TABLE ship (Name VARCHAR, Ship_ID VARCHAR)

Answer: [SQL] SELECT Name FROM ship WHERE NOT Ship_ID IN (SELECT Ship_ID FROM mission) [/SQL]


Question: Show the types of ships that have both ships with tonnage larger than 6000 and ships with tonnage smaller than 4000.

Answer: [SQL] SELECT TYPE FROM ship WHERE Tonnage > 6000 INTERSECT SELECT TYPE FROM ship WHERE Tonnage < 4000 [/SQL]


Question: Find the number of students in total.

Context: CREATE TABLE list (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM list [/SQL]


Question: Find the last names of students studying in room 111.

Context: CREATE TABLE list (lastname VARCHAR, classroom VARCHAR)

Answer: [SQL] SELECT lastname FROM list WHERE classroom = 111 [/SQL]


Question: Find the first names of students studying in room 108.

Context: CREATE TABLE list (firstname VARCHAR, classroom VARCHAR)

Answer: [SQL] SELECT firstname FROM list WHERE classroom = 108 [/SQL]


Question: What are the first names of students studying in room 107?

Answer: [SQL] SELECT DISTINCT firstname FROM list WHERE classroom = 107 [/SQL]


Question: For each classroom report the grade that is taught in it. Report just the classroom number and the grade number.

Context: CREATE TABLE list (classroom VARCHAR, grade VARCHAR)

Answer: [SQL] SELECT DISTINCT classroom, grade FROM list [/SQL]


Question: Which grade is studying in classroom 103?

Context: CREATE TABLE list (grade VARCHAR, classroom VARCHAR)

Answer: [SQL] SELECT DISTINCT grade FROM list WHERE classroom = 103 [/SQL]


Question: Find the grade studying in room 105.

Answer: [SQL] SELECT DISTINCT grade FROM list WHERE classroom = 105 [/SQL]


Question: Which classrooms are used by grade 4?

Answer: [SQL] SELECT DISTINCT classroom FROM list WHERE grade = 4 [/SQL]


Question: Which classrooms are used by grade 5?

Answer: [SQL] SELECT DISTINCT classroom FROM list WHERE grade = 5 [/SQL]


Question: Find the last names of the teachers that teach fifth grade.

Context: CREATE TABLE list (classroom VARCHAR); CREATE TABLE teachers (lastname VARCHAR, classroom VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE grade = 5 [/SQL]


Question: Find the first names of the teachers that teach first grade.

Context: CREATE TABLE list (classroom VARCHAR); CREATE TABLE teachers (firstname VARCHAR, classroom VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.firstname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE grade = 1 [/SQL]


Question: Find the first names of all the teachers that teach in classroom 110.

Context: CREATE TABLE teachers (firstname VARCHAR, classroom VARCHAR)

Answer: [SQL] SELECT firstname FROM teachers WHERE classroom = 110 [/SQL]


Question: Find the last names of teachers teaching in classroom 109.

Context: CREATE TABLE teachers (lastname VARCHAR, classroom VARCHAR)

Answer: [SQL] SELECT lastname FROM teachers WHERE classroom = 109 [/SQL]


Question: Report the first name and last name of all the teachers.

Context: CREATE TABLE teachers (firstname VARCHAR, lastname VARCHAR)

Answer: [SQL] SELECT DISTINCT firstname, lastname FROM teachers [/SQL]


Question: Report the first name and last name of all the students.

Context: CREATE TABLE list (firstname VARCHAR, lastname VARCHAR)

Answer: [SQL] SELECT DISTINCT firstname, lastname FROM list [/SQL]


Question: Find all students taught by OTHA MOYER. Output the first and last names of the students.

Context: CREATE TABLE list (firstname VARCHAR, lastname VARCHAR, classroom VARCHAR); CREATE TABLE teachers (classroom VARCHAR, firstname VARCHAR, lastname VARCHAR)

Answer: [SQL] SELECT T1.firstname, T1.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T2.firstname = "OTHA" AND T2.lastname = "MOYER" [/SQL]


Question: Find all students taught by MARROTTE KIRK. Output first and last names of students.

Answer: [SQL] SELECT T1.firstname, T1.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T2.firstname = "MARROTTE" AND T2.lastname = "KIRK" [/SQL]


Question: Find the first and last name of all the teachers that teach EVELINA BROMLEY.

Context: CREATE TABLE teachers (firstname VARCHAR, lastname VARCHAR, classroom VARCHAR); CREATE TABLE list (classroom VARCHAR, firstname VARCHAR, lastname VARCHAR)

Answer: [SQL] SELECT T2.firstname, T2.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T1.firstname = "EVELINA" AND T1.lastname = "BROMLEY" [/SQL]


Question: Find the last names of all the teachers that teach GELL TAMI.

Context: CREATE TABLE teachers (lastname VARCHAR, classroom VARCHAR); CREATE TABLE list (classroom VARCHAR, firstname VARCHAR, lastname VARCHAR)

Answer: [SQL] SELECT T2.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T1.firstname = "GELL" AND T1.lastname = "TAMI" [/SQL]


Question: How many students does LORIA ONDERSMA teaches?

Context: CREATE TABLE list (classroom VARCHAR); CREATE TABLE teachers (classroom VARCHAR, firstname VARCHAR, lastname VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T2.firstname = "LORIA" AND T2.lastname = "ONDERSMA" [/SQL]


Question: How many students does KAWA GORDON teaches?

Answer: [SQL] SELECT COUNT(*) FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T2.firstname = "KAWA" AND T2.lastname = "GORDON" [/SQL]


Question: Find the number of students taught by TARRING LEIA.

Answer: [SQL] SELECT COUNT(*) FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T2.firstname = "TARRING" AND T2.lastname = "LEIA" [/SQL]


Question: How many teachers does the student named CHRISSY NABOZNY have?

Context: CREATE TABLE teachers (classroom VARCHAR); CREATE TABLE list (classroom VARCHAR, firstname VARCHAR, lastname VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T1.firstname = "CHRISSY" AND T1.lastname = "NABOZNY" [/SQL]


Question: How many teachers does the student named MADLOCK RAY have?

Answer: [SQL] SELECT COUNT(*) FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T1.firstname = "MADLOCK" AND T1.lastname = "RAY" [/SQL]


Question: Find all first-grade students who are NOT taught by OTHA MOYER. Report their first and last names.

Context: CREATE TABLE list (firstname VARCHAR, lastname VARCHAR, classroom VARCHAR, grade VARCHAR); CREATE TABLE teachers (classroom VARCHAR, firstname VARCHAR, lastname VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.firstname, T1.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T1.grade = 1 EXCEPT SELECT T1.firstname, T1.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T2.firstname = "OTHA" AND T2.lastname = "MOYER" [/SQL]


Question: Find the last names of the students in third grade that are not taught by COVIN JEROME.

Context: CREATE TABLE list (lastname VARCHAR, classroom VARCHAR, grade VARCHAR); CREATE TABLE teachers (classroom VARCHAR, lastname VARCHAR, firstname VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T1.grade = 3 AND T2.firstname <> "COVIN" AND T2.lastname <> "JEROME" [/SQL]


Question: For each grade, report the grade, the number of classrooms in which it is taught and the total number of students in the grade.

Answer: [SQL] SELECT grade, COUNT(DISTINCT classroom), COUNT(*) FROM list GROUP BY grade [/SQL]


Question: For each classroom, report the classroom number and the number of grades using it.

Answer: [SQL] SELECT classroom, COUNT(DISTINCT grade) FROM list GROUP BY classroom [/SQL]


Question: Which classroom has the most students?

Context: CREATE TABLE list (classroom VARCHAR)

Answer: [SQL] SELECT classroom FROM list GROUP BY classroom ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Report the number of students in each classroom.

Context: CREATE TABLE list (classroom VARCHAR)

Answer: [SQL] SELECT classroom, COUNT(*) FROM list GROUP BY classroom [/SQL]


Question: For each grade 0 classroom, report the total number of students.

Answer: [SQL] SELECT classroom, COUNT(*) FROM list WHERE grade = "0" GROUP BY classroom [/SQL]


Question: Report the total number of students for each fourth-grade classroom.

Answer: [SQL] SELECT classroom, COUNT(*) FROM list WHERE grade = "4" GROUP BY classroom [/SQL]


Question: Find the name of the teacher who teaches the largest number of students.

Context: CREATE TABLE list (classroom VARCHAR); CREATE TABLE teachers (firstname VARCHAR, lastname VARCHAR, classroom VARCHAR)

Answer: [SQL] SELECT T2.firstname, T2.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom GROUP BY T2.firstname, T2.lastname ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the number of students in one classroom.

Context: CREATE TABLE list (classroom VARCHAR)

Answer: [SQL] SELECT COUNT(*), classroom FROM list GROUP BY classroom [/SQL]


Question: How many companies are headquartered in the US?

Context: CREATE TABLE company (Headquarters VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM company WHERE Headquarters = 'USA' [/SQL]


Question: List the names of companies by ascending number of sales.

Context: CREATE TABLE company (Name VARCHAR, Sales_in_Billion VARCHAR)

Answer: [SQL] SELECT Name FROM company ORDER BY Sales_in_Billion [/SQL]


Question: What are the headquarters and industries of all companies?

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

Answer: [SQL] SELECT Headquarters, Industry FROM company [/SQL]


Question: Show the names of companies in the banking or retailing industry?

Context: CREATE TABLE company (Name VARCHAR, Industry VARCHAR)

Answer: [SQL] SELECT Name FROM company WHERE Industry = "Banking" OR Industry = "Retailing" [/SQL]


Question: What is the maximum and minimum market value of companies?

Context: CREATE TABLE company (Market_Value_in_Billion INTEGER)

Answer: [SQL] SELECT MAX(Market_Value_in_Billion), MIN(Market_Value_in_Billion) FROM company [/SQL]


Question: What is the headquarter of the company with the largest sales?

Context: CREATE TABLE company (Headquarters VARCHAR, Sales_in_Billion VARCHAR)

Answer: [SQL] SELECT Headquarters FROM company ORDER BY Sales_in_Billion DESC LIMIT 1 [/SQL]


Question: Show the different headquarters and number of companies at each headquarter.

Answer: [SQL] SELECT Headquarters, COUNT(*) FROM company GROUP BY Headquarters [/SQL]


Question: Show the most common headquarter for companies.

Answer: [SQL] SELECT Headquarters FROM company GROUP BY Headquarters ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the headquarters that have at least two companies.

Answer: [SQL] SELECT Headquarters FROM company GROUP BY Headquarters HAVING COUNT(*) >= 2 [/SQL]


Question: Show the headquarters that have both companies in banking industry and companies in oil and gas industry.

Answer: [SQL] SELECT Headquarters FROM company WHERE Industry = "Banking" INTERSECT SELECT Headquarters FROM company WHERE Industry = "Oil and gas" [/SQL]


Question: Show the names of companies and of employees.

Context: CREATE TABLE company (Name VARCHAR, Company_ID VARCHAR); CREATE TABLE employment (People_ID VARCHAR, Company_ID VARCHAR); CREATE TABLE people (Name VARCHAR, People_ID VARCHAR)

Answer: [SQL] SELECT T3.Name, T2.Name FROM employment AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID JOIN company AS T3 ON T1.Company_ID = T3.Company_ID [/SQL]


Question: Show names of companies and that of employees in descending order of number of years working for that employee.

Context: CREATE TABLE people (Name VARCHAR, People_ID VARCHAR); CREATE TABLE company (Name VARCHAR, Company_ID VARCHAR); CREATE TABLE employment (People_ID VARCHAR, Company_ID VARCHAR, Year_working VARCHAR)

Answer: [SQL] SELECT T3.Name, T2.Name FROM employment AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID JOIN company AS T3 ON T1.Company_ID = T3.Company_ID ORDER BY T1.Year_working [/SQL]


Question: Show the names of employees that work for companies with sales bigger than 200.

Context: CREATE TABLE employment (People_ID VARCHAR, Company_ID VARCHAR); CREATE TABLE company (Company_ID VARCHAR, Sales_in_Billion INTEGER); CREATE TABLE people (Name VARCHAR, People_ID VARCHAR)

Answer: [SQL] SELECT T2.Name FROM employment AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID JOIN company AS T3 ON T1.Company_ID = T3.Company_ID WHERE T3.Sales_in_Billion > 200 [/SQL]


Question: Show the names of companies and the number of employees they have

Context: CREATE TABLE company (Name VARCHAR, Company_ID VARCHAR); CREATE TABLE people (People_ID VARCHAR); CREATE TABLE employment (People_ID VARCHAR, Company_ID VARCHAR)

Answer: [SQL] SELECT T3.Name, COUNT(*) FROM employment AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID JOIN company AS T3 ON T1.Company_ID = T3.Company_ID GROUP BY T3.Name [/SQL]


Question: List the names of people that are not employed by any company

Context: CREATE TABLE employment (Name VARCHAR, People_ID VARCHAR); CREATE TABLE people (Name VARCHAR, People_ID VARCHAR)

Answer: [SQL] SELECT Name FROM people WHERE NOT People_ID IN (SELECT People_ID FROM employment) [/SQL]


Question: list the names of the companies with more than 200 sales in the descending order of sales and profits.

Context: CREATE TABLE company (name VARCHAR, Sales_in_Billion INTEGER, Profits_in_Billion VARCHAR)

Answer: [SQL] SELECT name FROM company WHERE Sales_in_Billion > 200 ORDER BY Sales_in_Billion, Profits_in_Billion DESC [/SQL]


Question: How many film are there?

Context: CREATE TABLE film (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM film [/SQL]


Question: List the distinct director of all films.

Context: CREATE TABLE film (Director VARCHAR)

Answer: [SQL] SELECT DISTINCT Director FROM film [/SQL]


Question: What is the average ticket sales gross in dollars of films?

Context: CREATE TABLE film (Gross_in_dollar INTEGER)

Answer: [SQL] SELECT AVG(Gross_in_dollar) FROM film [/SQL]


Question: What are the low and high estimates of film markets?

Context: CREATE TABLE film_market_estimation (Low_Estimate VARCHAR, High_Estimate VARCHAR)

Answer: [SQL] SELECT Low_Estimate, High_Estimate FROM film_market_estimation [/SQL]


Question: What are the types of film market estimations in year 1995?

Context: CREATE TABLE film_market_estimation (TYPE VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT TYPE FROM film_market_estimation WHERE YEAR = 1995 [/SQL]


Question: What are the maximum and minimum number of cities in all markets.

Context: CREATE TABLE market (Number_cities INTEGER)

Answer: [SQL] SELECT MAX(Number_cities), MIN(Number_cities) FROM market [/SQL]


Question: How many markets have number of cities smaller than 300?

Answer: [SQL] SELECT COUNT(*) FROM market WHERE Number_cities < 300 [/SQL]


Question: List all countries of markets in ascending alphabetical order.

Context: CREATE TABLE market (Country VARCHAR)

Answer: [SQL] SELECT Country FROM market ORDER BY Country [/SQL]


Question: List all countries of markets in descending order of number of cities.

Context: CREATE TABLE market (Country VARCHAR, Number_cities VARCHAR)

Answer: [SQL] SELECT Country FROM market ORDER BY Number_cities DESC [/SQL]


Question: Please show the titles of films and the types of market estimations.

Context: CREATE TABLE film (Title VARCHAR, Film_ID VARCHAR); CREATE TABLE film_market_estimation (Type VARCHAR, Film_ID VARCHAR)

Answer: [SQL] SELECT T1.Title, T2.Type FROM film AS T1 JOIN film_market_estimation AS T2 ON T1.Film_ID = T2.Film_ID [/SQL]


Question: Show the distinct director of films with market estimation in the year of 1995.

Context: CREATE TABLE film (Director VARCHAR, Film_ID VARCHAR); CREATE TABLE film_market_estimation (Film_ID VARCHAR, Year VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.Director FROM film AS T1 JOIN film_market_estimation AS T2 ON T1.Film_ID = T2.Film_ID WHERE T2.Year = 1995 [/SQL]


Question: What is the average number of cities of markets with low film market estimate bigger than 10000?

Context: CREATE TABLE market (Number_cities INTEGER, Market_ID VARCHAR); CREATE TABLE film_market_estimation (Market_ID VARCHAR, Low_Estimate INTEGER)

Answer: [SQL] SELECT AVG(T2.Number_cities) FROM film_market_estimation AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID WHERE T1.Low_Estimate > 10000 [/SQL]


Question: Please list the countries and years of film market estimations.

Context: CREATE TABLE film_market_estimation (Year VARCHAR, Market_ID VARCHAR); CREATE TABLE market (Country VARCHAR, Market_ID VARCHAR)

Answer: [SQL] SELECT T2.Country, T1.Year FROM film_market_estimation AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID [/SQL]


Question: Please list the years of film market estimations when the market is in country "Japan" in descending order.

Context: CREATE TABLE film_market_estimation (Year VARCHAR, Market_ID VARCHAR); CREATE TABLE market (Market_ID VARCHAR, Country VARCHAR)

Answer: [SQL] SELECT T1.Year FROM film_market_estimation AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID WHERE T2.Country = "Japan" ORDER BY T1.Year DESC [/SQL]


Question: List the studios of each film and the number of films produced by that studio.

Context: CREATE TABLE film (Studio VARCHAR)

Answer: [SQL] SELECT Studio, COUNT(*) FROM film GROUP BY Studio [/SQL]


Question: List the name of film studio that have the most number of films.

Context: CREATE TABLE film (Studio VARCHAR)

Answer: [SQL] SELECT Studio FROM film GROUP BY Studio ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: List the names of studios that have at least two films.

Context: CREATE TABLE film (Studio VARCHAR)

Answer: [SQL] SELECT Studio FROM film GROUP BY Studio HAVING COUNT(*) >= 2 [/SQL]


Question: List the title of films that do not have any market estimation.

Context: CREATE TABLE film_market_estimation (Title VARCHAR, Film_ID VARCHAR); CREATE TABLE film (Title VARCHAR, Film_ID VARCHAR)

Answer: [SQL] SELECT Title FROM film WHERE NOT Film_ID IN (SELECT Film_ID FROM film_market_estimation) [/SQL]


Question: Show the studios that have produced films with director "Nicholas Meyer" and "Walter Hill".

Context: CREATE TABLE film (Studio VARCHAR, Director VARCHAR)

Answer: [SQL] SELECT Studio FROM film WHERE Director = "Nicholas Meyer" INTERSECT SELECT Studio FROM film WHERE Director = "Walter Hill" [/SQL]


Question: Find the titles and studios of the films that are produced by some film studios that contained the word "Universal".

Context: CREATE TABLE film (title VARCHAR, Studio VARCHAR)

Answer: [SQL] SELECT title, Studio FROM film WHERE Studio LIKE "%Universal%" [/SQL]


Question: Show the studios that have not produced films with director "Walter Hill".

Answer: [SQL] SELECT Studio FROM film EXCEPT SELECT Studio FROM film WHERE Director = "Walter Hill" [/SQL]


Question: List the studios which average gross is above 4500000.

Context: CREATE TABLE film (Studio VARCHAR, Gross_in_dollar INTEGER)

Answer: [SQL] SELECT Studio FROM film GROUP BY Studio HAVING AVG(Gross_in_dollar) >= 4500000 [/SQL]


Question: What is the title of the film that has the highest high market estimation.

Context: CREATE TABLE film_market_estimation (Film_ID VARCHAR); CREATE TABLE film (Film_ID VARCHAR)

Answer: [SQL] SELECT t1.title FROM film AS T1 JOIN film_market_estimation AS T2 ON T1.Film_ID = T2.Film_ID ORDER BY high_estimate DESC LIMIT 1 [/SQL]


Question: What are the titles and directors of the films were never presented in China?

Context: CREATE TABLE film (title VARCHAR, director VARCHAR, film_id VARCHAR, country VARCHAR); CREATE TABLE market (Market_ID VARCHAR); CREATE TABLE film_market_estimation (market_id VARCHAR)

Answer: [SQL] SELECT title, director FROM film WHERE NOT film_id IN (SELECT film_id FROM film_market_estimation AS T1 JOIN market AS T2 ON T1.market_id = T2.Market_ID WHERE country = 'China') [/SQL]


Question: How many calendar items do we have?

Context: CREATE TABLE Ref_calendar (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Ref_calendar [/SQL]


Question: Show all calendar dates and day Numbers.

Context: CREATE TABLE Ref_calendar (calendar_date VARCHAR, day_Number VARCHAR)

Answer: [SQL] SELECT calendar_date, day_Number FROM Ref_calendar [/SQL]


Question: Show the number of document types.

Context: CREATE TABLE Ref_document_types (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Ref_document_types [/SQL]


Question: List all document type codes and document type names.

Context: CREATE TABLE Ref_document_types (document_type_code VARCHAR, document_type_name VARCHAR)

Answer: [SQL] SELECT document_type_code, document_type_name FROM Ref_document_types [/SQL]


Question: What is the name and description for document type code RV?

Context: CREATE TABLE Ref_document_types (document_type_name VARCHAR, document_type_description VARCHAR, document_type_code VARCHAR)

Answer: [SQL] SELECT document_type_name, document_type_description FROM Ref_document_types WHERE document_type_code = "RV" [/SQL]


Question: What is the document type code for document type "Paper"?

Answer: [SQL] SELECT document_type_code FROM Ref_document_types WHERE document_type_name = "Paper" [/SQL]


Question: Show the number of documents with document type code CV or BK.

Context: CREATE TABLE All_documents (document_type_code VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM All_documents WHERE document_type_code = "CV" OR document_type_code = "BK" [/SQL]


Question: What is the date when the document "Marry CV" was stored?

Context: CREATE TABLE All_documents (date_stored VARCHAR, Document_name VARCHAR)

Answer: [SQL] SELECT date_stored FROM All_documents WHERE Document_name = "Marry CV" [/SQL]


Question: What is the day Number and date of all the documents?

Context: CREATE TABLE All_documents (Date_Stored VARCHAR, date_stored VARCHAR); CREATE TABLE Ref_calendar (day_Number VARCHAR, calendar_date VARCHAR)

Answer: [SQL] SELECT T2.day_Number, T1.Date_Stored FROM All_documents AS T1 JOIN Ref_calendar AS T2 ON T1.date_stored = T2.calendar_date [/SQL]


Question: What is the document type name for the document with name "How to read a book"?

Context: CREATE TABLE Ref_document_types (document_type_name VARCHAR, document_type_code VARCHAR); CREATE TABLE All_documents (document_type_code VARCHAR, document_name VARCHAR)

Answer: [SQL] SELECT T2.document_type_name FROM All_documents AS T1 JOIN Ref_document_types AS T2 ON T1.document_type_code = T2.document_type_code WHERE T1.document_name = "How to read a book" [/SQL]


Question: Show the number of locations.

Context: CREATE TABLE Ref_locations (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Ref_locations [/SQL]


Question: List all location codes and location names.

Context: CREATE TABLE Ref_locations (location_code VARCHAR, location_name VARCHAR)

Answer: [SQL] SELECT location_code, location_name FROM Ref_locations [/SQL]


Question: What are the name and description for location code x?

Context: CREATE TABLE Ref_locations (location_name VARCHAR, location_description VARCHAR, location_code VARCHAR)

Answer: [SQL] SELECT location_name, location_description FROM Ref_locations WHERE location_code = "x" [/SQL]


Question: What is the location code for the country "Canada"?

Answer: [SQL] SELECT location_code FROM Ref_locations WHERE location_name = "Canada" [/SQL]


Question: How many roles are there?

Context: CREATE TABLE ROLES (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM ROLES [/SQL]


Question: List all role codes, role names, and role descriptions.

Context: CREATE TABLE ROLES (role_code VARCHAR, role_name VARCHAR, role_description VARCHAR)

Answer: [SQL] SELECT role_code, role_name, role_description FROM ROLES [/SQL]


Question: What are the name and description for role code "MG"?

Context: CREATE TABLE ROLES (role_name VARCHAR, role_description VARCHAR, role_code VARCHAR)

Answer: [SQL] SELECT role_name, role_description FROM ROLES WHERE role_code = "MG" [/SQL]


Question: Show the description for role name "Proof Reader".

Context: CREATE TABLE ROLES (role_description VARCHAR, role_name VARCHAR)

Answer: [SQL] SELECT role_description FROM ROLES WHERE role_name = "Proof Reader" [/SQL]


Question: Show the name, role code, and date of birth for the employee with name 'Armani'.

Context: CREATE TABLE Employees (employee_name VARCHAR, role_code VARCHAR, date_of_birth VARCHAR, employee_Name VARCHAR)

Answer: [SQL] SELECT employee_name, role_code, date_of_birth FROM Employees WHERE employee_Name = 'Armani' [/SQL]


Question: What is the id for the employee called Ebba?

Context: CREATE TABLE Employees (employee_ID VARCHAR, employee_name VARCHAR)

Answer: [SQL] SELECT employee_ID FROM Employees WHERE employee_name = "Ebba" [/SQL]


Question: Show the names of all the employees with role "HR".

Context: CREATE TABLE Employees (employee_name VARCHAR, role_code VARCHAR)

Answer: [SQL] SELECT employee_name FROM Employees WHERE role_code = "HR" [/SQL]


Question: Show all role codes and the number of employees in each role.

Context: CREATE TABLE Employees (role_code VARCHAR)

Answer: [SQL] SELECT role_code, COUNT(*) FROM Employees GROUP BY role_code [/SQL]


Question: What is the role code with the largest number of employees?

Answer: [SQL] SELECT role_code FROM Employees GROUP BY role_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show all role codes with at least 3 employees.

Answer: [SQL] SELECT role_code FROM Employees GROUP BY role_code HAVING COUNT(*) >= 3 [/SQL]


Question: Show the role code with the least employees.

Answer: [SQL] SELECT role_code FROM Employees GROUP BY role_code ORDER BY COUNT(*) LIMIT 1 [/SQL]


Question: What is the role name and role description for employee called Ebba?

Context: CREATE TABLE Employees (role_code VARCHAR, employee_name VARCHAR); CREATE TABLE ROLES (role_name VARCHAR, role_description VARCHAR, role_code VARCHAR)

Answer: [SQL] SELECT T2.role_name, T2.role_description FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code = T2.role_code WHERE T1.employee_name = "Ebba" [/SQL]


Question: Show the names of employees with role name Editor.

Context: CREATE TABLE ROLES (role_code VARCHAR, role_name VARCHAR); CREATE TABLE Employees (employee_name VARCHAR, role_code VARCHAR)

Answer: [SQL] SELECT T1.employee_name FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code = T2.role_code WHERE T2.role_name = "Editor" [/SQL]


Question: Show the employee ids for all employees with role name "Human Resource" or "Manager".

Context: CREATE TABLE Employees (employee_id VARCHAR, role_code VARCHAR); CREATE TABLE ROLES (role_code VARCHAR, role_name VARCHAR)

Answer: [SQL] SELECT T1.employee_id FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code = T2.role_code WHERE T2.role_name = "Human Resource" OR T2.role_name = "Manager" [/SQL]


Question: What are the different location codes for documents?

Context: CREATE TABLE Document_locations (location_code VARCHAR)

Answer: [SQL] SELECT DISTINCT location_code FROM Document_locations [/SQL]


Question: Show the location name for document "Robin CV".

Context: CREATE TABLE Ref_locations (location_name VARCHAR, location_code VARCHAR); CREATE TABLE All_documents (document_id VARCHAR, document_name VARCHAR); CREATE TABLE Document_locations (document_id VARCHAR, location_code VARCHAR)

Answer: [SQL] SELECT T3.location_name FROM All_documents AS T1 JOIN Document_locations AS T2 ON T1.document_id = T2.document_id JOIN Ref_locations AS T3 ON T2.location_code = T3.location_code WHERE T1.document_name = "Robin CV" [/SQL]


Question: Show the location code, the starting date and ending data in that location for all the documents.

Context: CREATE TABLE Document_locations (location_code VARCHAR, date_in_location_from VARCHAR, date_in_locaton_to VARCHAR)

Answer: [SQL] SELECT location_code, date_in_location_from, date_in_locaton_to FROM Document_locations [/SQL]


Question: What is "the date in location from" and "the date in location to" for the document with name "Robin CV"?

Context: CREATE TABLE All_documents (document_id VARCHAR, document_name VARCHAR); CREATE TABLE Document_locations (date_in_location_from VARCHAR, date_in_locaton_to VARCHAR, document_id VARCHAR)

Answer: [SQL] SELECT T1.date_in_location_from, T1.date_in_locaton_to FROM Document_locations AS T1 JOIN All_documents AS T2 ON T1.document_id = T2.document_id WHERE T2.document_name = "Robin CV" [/SQL]


Question: Show the location codes and the number of documents in each location.

Answer: [SQL] SELECT location_code, COUNT(*) FROM Document_locations GROUP BY location_code [/SQL]


Question: What is the location code with the most documents?

Answer: [SQL] SELECT location_code FROM Document_locations GROUP BY location_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the location codes with at least 3 documents.

Answer: [SQL] SELECT location_code FROM Document_locations GROUP BY location_code HAVING COUNT(*) >= 3 [/SQL]


Question: Show the location name and code with the least documents.

Context: CREATE TABLE Document_locations (location_code VARCHAR); CREATE TABLE Ref_locations (location_name VARCHAR, location_code VARCHAR)

Answer: [SQL] SELECT T2.location_name, T1.location_code FROM Document_locations AS T1 JOIN Ref_locations AS T2 ON T1.location_code = T2.location_code GROUP BY T1.location_code ORDER BY COUNT(*) LIMIT 1 [/SQL]


Question: What are the names of the employees who authorised the destruction and the employees who destroyed the corresponding documents?

Context: CREATE TABLE Employees (employee_name VARCHAR, employee_id VARCHAR); CREATE TABLE Documents_to_be_destroyed (Destruction_Authorised_by_Employee_ID VARCHAR, Destroyed_by_Employee_ID VARCHAR)

Answer: [SQL] SELECT T2.employee_name, T3.employee_name FROM Documents_to_be_destroyed AS T1 JOIN Employees AS T2 ON T1.Destruction_Authorised_by_Employee_ID = T2.employee_id JOIN Employees AS T3 ON T1.Destroyed_by_Employee_ID = T3.employee_id [/SQL]


Question: Show the id of each employee and the number of document destruction authorised by that employee.

Context: CREATE TABLE Documents_to_be_destroyed (Destruction_Authorised_by_Employee_ID VARCHAR)

Answer: [SQL] SELECT Destruction_Authorised_by_Employee_ID, COUNT(*) FROM Documents_to_be_destroyed GROUP BY Destruction_Authorised_by_Employee_ID [/SQL]


Question: Show the employee ids and the number of documents destroyed by each employee.

Context: CREATE TABLE Documents_to_be_destroyed (Destroyed_by_Employee_ID VARCHAR)

Answer: [SQL] SELECT Destroyed_by_Employee_ID, COUNT(*) FROM Documents_to_be_destroyed GROUP BY Destroyed_by_Employee_ID [/SQL]


Question: Show the ids of the employees who don't authorize destruction for any document.

Context: CREATE TABLE Documents_to_be_destroyed (employee_id VARCHAR, Destruction_Authorised_by_Employee_ID VARCHAR); CREATE TABLE Employees (employee_id VARCHAR, Destruction_Authorised_by_Employee_ID VARCHAR)

Answer: [SQL] SELECT employee_id FROM Employees EXCEPT SELECT Destruction_Authorised_by_Employee_ID FROM Documents_to_be_destroyed [/SQL]


Question: Show the ids of all employees who have authorized destruction.

Answer: [SQL] SELECT DISTINCT Destruction_Authorised_by_Employee_ID FROM Documents_to_be_destroyed [/SQL]


Question: Show the ids of all employees who have destroyed a document.

Answer: [SQL] SELECT DISTINCT Destroyed_by_Employee_ID FROM Documents_to_be_destroyed [/SQL]


Question: Show the ids of all employees who don't destroy any document.

Context: CREATE TABLE Employees (employee_id VARCHAR, Destroyed_by_Employee_ID VARCHAR); CREATE TABLE Documents_to_be_destroyed (employee_id VARCHAR, Destroyed_by_Employee_ID VARCHAR)

Answer: [SQL] SELECT employee_id FROM Employees EXCEPT SELECT Destroyed_by_Employee_ID FROM Documents_to_be_destroyed [/SQL]


Question: Show the ids of all employees who have either destroyed a document or made an authorization to do this.

Context: CREATE TABLE Documents_to_be_destroyed (Destroyed_by_Employee_ID VARCHAR, Destruction_Authorised_by_Employee_ID VARCHAR)

Answer: [SQL] SELECT Destroyed_by_Employee_ID FROM Documents_to_be_destroyed UNION SELECT Destruction_Authorised_by_Employee_ID FROM Documents_to_be_destroyed [/SQL]


Question: What are the names of all clubs?

Context: CREATE TABLE club (clubname VARCHAR)

Answer: [SQL] SELECT clubname FROM club [/SQL]


Question: How many students are there?

Context: CREATE TABLE student (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM student [/SQL]


Question: What are the first names of all the students?

Context: CREATE TABLE student (fname VARCHAR)

Answer: [SQL] SELECT DISTINCT fname FROM student [/SQL]


Question: Find the last names of the members of the club "Bootup Baltimore".

Context: CREATE TABLE club (clubid VARCHAR, clubname VARCHAR); CREATE TABLE student (lname VARCHAR, stuid VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR)

Answer: [SQL] SELECT t3.lname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Bootup Baltimore" [/SQL]


Question: Who are the members of the club named "Hopkins Student Enterprises"? Show the last name.

Answer: [SQL] SELECT t3.lname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Hopkins Student Enterprises" [/SQL]


Question: How many members does the club "Tennis Club" has?

Context: CREATE TABLE club (clubid VARCHAR, clubname VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR); CREATE TABLE student (stuid VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Tennis Club" [/SQL]


Question: Find the number of members of club "Pen and Paper Gaming".

Answer: [SQL] SELECT COUNT(*) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Pen and Paper Gaming" [/SQL]


Question: How many clubs does "Linda Smith" belong to?

Context: CREATE TABLE student (stuid VARCHAR, fname VARCHAR, lname VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR); CREATE TABLE club (clubid VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t3.fname = "Linda" AND t3.lname = "Smith" [/SQL]


Question: Find the number of clubs where "Tracy Kim" is a member.

Answer: [SQL] SELECT COUNT(*) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t3.fname = "Tracy" AND t3.lname = "Kim" [/SQL]


Question: Find all the female members of club "Bootup Baltimore". Show the first name and last name.

Context: CREATE TABLE club (clubid VARCHAR, clubname VARCHAR); CREATE TABLE student (fname VARCHAR, lname VARCHAR, stuid VARCHAR, sex VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR)

Answer: [SQL] SELECT t3.fname, t3.lname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Bootup Baltimore" AND t3.sex = "F" [/SQL]


Question: Find all the male members of club "Hopkins Student Enterprises". Show the first name and last name.

Answer: [SQL] SELECT t3.fname, t3.lname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Hopkins Student Enterprises" AND t3.sex = "M" [/SQL]


Question: Find all members of "Bootup Baltimore" whose major is "600". Show the first name and last name.

Context: CREATE TABLE club (clubid VARCHAR, clubname VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR); CREATE TABLE student (fname VARCHAR, lname VARCHAR, stuid VARCHAR, major VARCHAR)

Answer: [SQL] SELECT t3.fname, t3.lname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Bootup Baltimore" AND t3.major = "600" [/SQL]


Question: Which club has the most members majoring in "600"?

Context: CREATE TABLE student (stuid VARCHAR, major VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR); CREATE TABLE club (clubname VARCHAR, clubid VARCHAR)

Answer: [SQL] SELECT t1.clubname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t3.major = "600" GROUP BY t1.clubname ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the name of the club that has the most female students.

Context: CREATE TABLE student (stuid VARCHAR, sex VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR); CREATE TABLE club (clubname VARCHAR, clubid VARCHAR)

Answer: [SQL] SELECT t1.clubname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t3.sex = "F" GROUP BY t1.clubname ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the description of the club named "Tennis Club"?

Context: CREATE TABLE club (clubdesc VARCHAR, clubname VARCHAR)

Answer: [SQL] SELECT clubdesc FROM club WHERE clubname = "Tennis Club" [/SQL]


Question: Find the description of the club "Pen and Paper Gaming".

Answer: [SQL] SELECT clubdesc FROM club WHERE clubname = "Pen and Paper Gaming" [/SQL]


Question: What is the location of the club named "Tennis Club"?

Context: CREATE TABLE club (clublocation VARCHAR, clubname VARCHAR)

Answer: [SQL] SELECT clublocation FROM club WHERE clubname = "Tennis Club" [/SQL]


Question: Find the location of the club "Pen and Paper Gaming".

Answer: [SQL] SELECT clublocation FROM club WHERE clubname = "Pen and Paper Gaming" [/SQL]


Question: Where is the club "Hopkins Student Enterprises" located?

Answer: [SQL] SELECT clublocation FROM club WHERE clubname = "Hopkins Student Enterprises" [/SQL]


Question: Find the name of all the clubs at "AKW".

Context: CREATE TABLE club (clubname VARCHAR, clublocation VARCHAR)

Answer: [SQL] SELECT clubname FROM club WHERE clublocation = "AKW" [/SQL]


Question: How many clubs are located at "HHH"?

Context: CREATE TABLE club (clublocation VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM club WHERE clublocation = "HHH" [/SQL]


Question: What are the first and last name of the president of the club "Bootup Baltimore"?

Context: CREATE TABLE club (clubid VARCHAR, clubname VARCHAR); CREATE TABLE student (fname VARCHAR, lname VARCHAR, stuid VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR, position VARCHAR)

Answer: [SQL] SELECT t3.fname, t3.lname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Bootup Baltimore" AND t2.position = "President" [/SQL]


Question: Who is the "CTO" of club "Hopkins Student Enterprises"? Show the first name and last name.

Answer: [SQL] SELECT t3.fname, t3.lname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Hopkins Student Enterprises" AND t2.position = "CTO" [/SQL]


Question: How many different roles are there in the club "Bootup Baltimore"?

Context: CREATE TABLE club (clubid VARCHAR, clubname VARCHAR); CREATE TABLE member_of_club (position VARCHAR, clubid VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT t2.position) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid WHERE t1.clubname = "Bootup Baltimore" [/SQL]


Question: How many members of "Bootup Baltimore" are older than 18?

Context: CREATE TABLE club (clubid VARCHAR, clubname VARCHAR); CREATE TABLE student (stuid VARCHAR, age VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Bootup Baltimore" AND t3.age > 18 [/SQL]


Question: How many members of club "Bootup Baltimore" are younger than 18?

Answer: [SQL] SELECT COUNT(*) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Bootup Baltimore" AND t3.age < 18 [/SQL]


Question: Find the names of all the clubs that have at least a member from the city with city code "BAL".

Context: CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR); CREATE TABLE club (clubname VARCHAR, clubid VARCHAR); CREATE TABLE student (stuid VARCHAR, city_code VARCHAR)

Answer: [SQL] SELECT DISTINCT t1.clubname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t3.city_code = "BAL" [/SQL]


Question: Find the names of the clubs that have at least a member from the city with city code "HOU".

Answer: [SQL] SELECT DISTINCT t1.clubname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t3.city_code = "HOU" [/SQL]


Question: How many clubs does the student named "Eric Tai" belong to?

Context: CREATE TABLE student (stuid VARCHAR, fname VARCHAR, lname VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR); CREATE TABLE club (clubname VARCHAR, clubid VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT t1.clubname) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t3.fname = "Eric" AND t3.lname = "Tai" [/SQL]


Question: List the clubs having "Davis Steven" as a member.

Answer: [SQL] SELECT DISTINCT t1.clubname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t3.fname = "Davis" AND t3.lname = "Steven" [/SQL]


Question: List the clubs that have at least a member with advisor "1121".

Context: CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR); CREATE TABLE club (clubname VARCHAR, clubid VARCHAR); CREATE TABLE student (stuid VARCHAR, advisor VARCHAR)

Answer: [SQL] SELECT DISTINCT t1.clubname FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t3.advisor = 1121 [/SQL]


Question: What is the average age of the members of the club "Bootup Baltimore"?

Context: CREATE TABLE club (clubid VARCHAR, clubname VARCHAR); CREATE TABLE student (age INTEGER, stuid VARCHAR); CREATE TABLE member_of_club (clubid VARCHAR, stuid VARCHAR)

Answer: [SQL] SELECT AVG(t3.age) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Bootup Baltimore" [/SQL]


Question: Find the average age of members of the club "Hopkins Student Enterprises".

Answer: [SQL] SELECT AVG(t3.age) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Hopkins Student Enterprises" [/SQL]


Question: Retrieve the average age of members of the club "Tennis Club".

Answer: [SQL] SELECT AVG(t3.age) FROM club AS t1 JOIN member_of_club AS t2 ON t1.clubid = t2.clubid JOIN student AS t3 ON t2.stuid = t3.stuid WHERE t1.clubname = "Tennis Club" [/SQL]


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)

Answer: [SQL] 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' [/SQL]


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)

Answer: [SQL] 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' [/SQL]


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)

Answer: [SQL] 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' [/SQL]


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)

Answer: [SQL] 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' [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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)

Answer: [SQL] 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 [/SQL]


Question: Which organisation type hires most research staff?

Answer: [SQL] 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 [/SQL]


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)

Answer: [SQL] 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' [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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)

Answer: [SQL] SELECT project_details FROM Projects WHERE NOT project_id IN (SELECT project_id FROM Project_Staff WHERE role_code = 'researcher') [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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)

Answer: [SQL] SELECT date_from, date_to FROM Project_Staff WHERE role_code = 'researcher' [/SQL]


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

Context: CREATE TABLE Project_Staff (role_code VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT role_code) FROM Project_Staff [/SQL]


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)

Answer: [SQL] SELECT SUM(grant_amount), organisation_id FROM Grants GROUP BY organisation_id [/SQL]


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)

Answer: [SQL] 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%' [/SQL]


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)

Answer: [SQL] 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(*) [/SQL]


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

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

Answer: [SQL] SELECT role_description FROM Staff_Roles WHERE role_code = 'researcher' [/SQL]


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

Context: CREATE TABLE Project_Staff (date_from VARCHAR)

Answer: [SQL] SELECT date_from FROM Project_Staff ORDER BY date_from LIMIT 1 [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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)

Answer: [SQL] SELECT project_details FROM Projects WHERE NOT project_id IN (SELECT project_id FROM Project_outcomes) [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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

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

Answer: [SQL] SELECT document_type_code FROM Document_Types WHERE document_description LIKE 'Initial%' [/SQL]


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)

Answer: [SQL] 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' [/SQL]


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

Context: CREATE TABLE Documents (grant_id VARCHAR)

Answer: [SQL] SELECT grant_id, COUNT(*) FROM Documents GROUP BY grant_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


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)

Answer: [SQL] 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' [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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

Context: CREATE TABLE Project_outcomes (outcome_code VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Project_outcomes WHERE outcome_code = 'Patent' [/SQL]


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)

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


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

Context: CREATE TABLE Project_Staff (date_to VARCHAR)

Answer: [SQL] SELECT date_to FROM Project_Staff ORDER BY date_to DESC LIMIT 1 [/SQL]


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)

Answer: [SQL] 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' [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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

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

Answer: [SQL] SELECT project_details FROM Projects WHERE organisation_id IN (SELECT organisation_id FROM Projects GROUP BY organisation_id ORDER BY COUNT(*) DESC LIMIT 1) [/SQL]


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

Context: CREATE TABLE Research_Staff (staff_details VARCHAR)

Answer: [SQL] SELECT staff_details FROM Research_Staff ORDER BY staff_details [/SQL]


Question: How many tasks are there in total?

Context: CREATE TABLE Tasks (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Tasks [/SQL]


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)

Answer: [SQL] 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 [/SQL]


Question: What are the staff roles of the staff who

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

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


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)

Answer: [SQL] SELECT T1.outcome_description FROM Research_outcomes AS T1 JOIN Project_outcomes AS T2 ON T1.outcome_code = T2.outcome_code [/SQL]


Question: Which role is most common for the staff?

Context: CREATE TABLE Project_Staff (role_code VARCHAR)

Answer: [SQL] SELECT role_code FROM Project_Staff GROUP BY role_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: How many friends does Dan have?

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

Answer: [SQL] SELECT COUNT(T2.friend) FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T1.name = 'Dan' [/SQL]


Question: How many females does this network has?

Context: CREATE TABLE Person (gender VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Person WHERE gender = 'female' [/SQL]


Question: What is the average age for all person?

Context: CREATE TABLE Person (age INTEGER)

Answer: [SQL] SELECT AVG(age) FROM Person [/SQL]


Question: How many different cities are they from?

Context: CREATE TABLE Person (city VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT city) FROM Person [/SQL]


Question: How many type of jobs do they have?

Context: CREATE TABLE Person (job VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT job) FROM Person [/SQL]


Question: Who is the oldest person?

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

Answer: [SQL] SELECT name FROM Person WHERE age = (SELECT MAX(age) FROM person) [/SQL]


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)

Answer: [SQL] SELECT name FROM Person WHERE job = 'student' AND age = (SELECT MAX(age) FROM person WHERE job = 'student') [/SQL]


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)

Answer: [SQL] SELECT name FROM Person WHERE gender = 'male' AND age = (SELECT MIN(age) FROM person WHERE gender = 'male') [/SQL]


Question: How old is the doctor named Zach?

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

Answer: [SQL] SELECT age FROM Person WHERE job = 'doctor' AND name = 'Zach' [/SQL]


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

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

Answer: [SQL] SELECT name FROM Person WHERE age < 30 [/SQL]


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

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

Answer: [SQL] SELECT COUNT(*) FROM Person WHERE age > 30 AND job = 'engineer' [/SQL]


Question: What is the average age for each gender?

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

Answer: [SQL] SELECT AVG(age), gender FROM Person GROUP BY gender [/SQL]


Question: What is average age for different job title?

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

Answer: [SQL] SELECT AVG(age), job FROM Person GROUP BY job [/SQL]


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

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

Answer: [SQL] SELECT AVG(age), job FROM Person WHERE gender = 'male' GROUP BY job [/SQL]


Question: What is minimum age for different job title?

Answer: [SQL] SELECT MIN(age), job FROM Person GROUP BY job [/SQL]


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

Answer: [SQL] SELECT COUNT(*), gender FROM Person WHERE age < 40 GROUP BY gender [/SQL]


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)

Answer: [SQL] SELECT name FROM Person WHERE age > (SELECT MIN(age) FROM person WHERE job = 'engineer') ORDER BY age [/SQL]


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)

Answer: [SQL] SELECT COUNT(*) FROM Person WHERE age > (SELECT MAX(age) FROM person WHERE job = 'engineer') [/SQL]


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

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

Answer: [SQL] SELECT name, job FROM Person ORDER BY name [/SQL]


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

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

Answer: [SQL] SELECT name FROM Person ORDER BY age DESC [/SQL]


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

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

Answer: [SQL] SELECT name FROM Person WHERE gender = 'male' ORDER BY age [/SQL]


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)

Answer: [SQL] SELECT T1.name, T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Dan' INTERSECT SELECT T1.name, T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Alice' [/SQL]


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

Answer: [SQL] SELECT DISTINCT T1.name, T1.age FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Dan' OR T2.friend = 'Alice' [/SQL]


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)

Answer: [SQL] SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age > 40) INTERSECT SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age < 30) [/SQL]


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

Answer: [SQL] SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend IN (SELECT name FROM Person WHERE age > 40) 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) [/SQL]


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)

Answer: [SQL] 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' [/SQL]


Question: Find the person who has exactly one friend.

Context: CREATE TABLE PersonFriend (name VARCHAR)

Answer: [SQL] SELECT name FROM PersonFriend GROUP BY name HAVING COUNT(*) = 1 [/SQL]


Question: Who are the friends of Bob?

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

Answer: [SQL] SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T1.name = 'Bob' [/SQL]


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

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

Answer: [SQL] SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Bob' [/SQL]


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)

Answer: [SQL] SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name WHERE T2.friend = 'Zach' AND T1.gender = 'female' [/SQL]


Question: Find the female friends of Alice.

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

Answer: [SQL] SELECT T2.friend FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T2.name = 'Alice' AND T1.gender = 'female' [/SQL]


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)

Answer: [SQL] 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' [/SQL]


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)

Answer: [SQL] SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.city = 'new york city' [/SQL]


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)

Answer: [SQL] 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) [/SQL]


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)

Answer: [SQL] 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) [/SQL]


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

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

Answer: [SQL] SELECT friend FROM PersonFriend WHERE name = 'Zach' AND YEAR = (SELECT MAX(YEAR) FROM PersonFriend WHERE name = 'Zach') [/SQL]


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)

Answer: [SQL] 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') [/SQL]


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)

Answer: [SQL] SELECT name FROM PersonFriend WHERE friend = 'Alice' AND YEAR = (SELECT MIN(YEAR) FROM PersonFriend WHERE friend = 'Alice') [/SQL]


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)

Answer: [SQL] 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') [/SQL]


Question: Who is the person that has no friend?

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

Answer: [SQL] SELECT name FROM person EXCEPT SELECT name FROM PersonFriend [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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)

Answer: [SQL] SELECT COUNT(DISTINCT name) FROM PersonFriend WHERE NOT friend IN (SELECT name FROM person WHERE city = 'Austin') [/SQL]


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)

Answer: [SQL] 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' [/SQL]


Question: How many members are there?

Context: CREATE TABLE member (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM member [/SQL]


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

Context: CREATE TABLE member (Name VARCHAR)

Answer: [SQL] SELECT Name FROM member ORDER BY Name [/SQL]


Question: What are the names and countries of members?

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

Answer: [SQL] SELECT Name, Country FROM member [/SQL]


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

Answer: [SQL] SELECT Name FROM member WHERE Country = "United States" OR Country = "Canada" [/SQL]


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

Context: CREATE TABLE member (Country VARCHAR)

Answer: [SQL] SELECT Country, COUNT(*) FROM member GROUP BY Country [/SQL]


Question: Show the most common country across members.

Context: CREATE TABLE member (Country VARCHAR)

Answer: [SQL] SELECT Country FROM member GROUP BY Country ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Which countries have more than two members?

Context: CREATE TABLE member (Country VARCHAR)

Answer: [SQL] SELECT Country FROM member GROUP BY Country HAVING COUNT(*) > 2 [/SQL]


Question: Show the leader names and locations of colleges.

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

Answer: [SQL] SELECT Leader_Name, College_Location FROM college [/SQL]


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)

Answer: [SQL] SELECT T2.Name, T1.Name FROM college AS T1 JOIN member AS T2 ON T1.College_ID = T2.College_ID [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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)

Answer: [SQL] SELECT DISTINCT T1.Leader_Name FROM college AS T1 JOIN member AS T2 ON T1.College_ID = T2.College_ID WHERE T2.Country = "Canada" [/SQL]


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)

Answer: [SQL] SELECT T1.Name, T2.Decoration_Theme FROM member AS T1 JOIN round AS T2 ON T1.Member_ID = T2.Member_ID [/SQL]


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)

Answer: [SQL] SELECT T1.Name FROM member AS T1 JOIN round AS T2 ON T1.Member_ID = T2.Member_ID WHERE T2.Rank_in_Round > 3 [/SQL]


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)

Answer: [SQL] SELECT T1.Name FROM member AS T1 JOIN round AS T2 ON T1.Member_ID = T2.Member_ID ORDER BY Rank_in_Round [/SQL]


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)

Answer: [SQL] SELECT Name FROM member WHERE NOT Member_ID IN (SELECT Member_ID FROM round) [/SQL]


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)

Answer: [SQL] SELECT document_name, access_count FROM documents ORDER BY document_name [/SQL]


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?

Answer: [SQL] SELECT document_name, access_count FROM documents ORDER BY access_count DESC LIMIT 1 [/SQL]


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

Context: CREATE TABLE documents (document_type_code VARCHAR)

Answer: [SQL] SELECT document_type_code FROM documents GROUP BY document_type_code HAVING COUNT(*) > 4 [/SQL]


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)

Answer: [SQL] SELECT SUM(access_count) FROM documents GROUP BY document_type_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the average access count of documents?

Context: CREATE TABLE documents (access_count INTEGER)

Answer: [SQL] SELECT AVG(access_count) FROM documents [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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

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

Answer: [SQL] SELECT document_type_code FROM documents WHERE document_name = "David CV" [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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

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

Answer: [SQL] SELECT document_type_code FROM documents GROUP BY document_type_code HAVING SUM(access_count) > 10000 [/SQL]


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)

Answer: [SQL] 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" [/SQL]


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)

Answer: [SQL] SELECT document_name FROM documents WHERE NOT document_code IN (SELECT document_code FROM document_sections) [/SQL]


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)

Answer: [SQL] SELECT user_name, password FROM users GROUP BY role_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


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)

Answer: [SQL] 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" [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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)

Answer: [SQL] 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 [/SQL]


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

Context: CREATE TABLE documents (document_name VARCHAR)

Answer: [SQL] SELECT document_name FROM documents WHERE document_name LIKE "%CV%" [/SQL]


Question: How many users are logged in?

Context: CREATE TABLE users (user_login VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM users WHERE user_login = 1 [/SQL]


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)

Answer: [SQL] 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) [/SQL]


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

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

Answer: [SQL] SELECT AVG(access_count) FROM documents GROUP BY document_structure_code ORDER BY COUNT(*) LIMIT 1 [/SQL]


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

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

Answer: [SQL] SELECT image_name, image_url FROM images ORDER BY image_name [/SQL]


Question: Find the number of users in each role.

Context: CREATE TABLE users (role_code VARCHAR)

Answer: [SQL] SELECT COUNT(*), role_code FROM users GROUP BY role_code [/SQL]


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

Context: CREATE TABLE documents (document_type_code VARCHAR)

Answer: [SQL] SELECT document_type_code FROM documents GROUP BY document_type_code HAVING COUNT(*) > 2 [/SQL]


Question: How many companies are there?

Context: CREATE TABLE Companies (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Companies [/SQL]


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

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

Answer: [SQL] SELECT name FROM Companies ORDER BY Market_Value_billion DESC [/SQL]


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

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

Answer: [SQL] SELECT name FROM Companies WHERE Headquarters <> 'USA' [/SQL]


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)

Answer: [SQL] SELECT name, Assets_billion FROM Companies ORDER BY name [/SQL]


Question: What are the average profits of companies?

Context: CREATE TABLE Companies (Profits_billion INTEGER)

Answer: [SQL] SELECT AVG(Profits_billion) FROM Companies [/SQL]


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)

Answer: [SQL] SELECT MAX(Sales_billion), MIN(Sales_billion) FROM Companies WHERE Industry <> "Banking" [/SQL]


Question: How many different industries are the companies in?

Context: CREATE TABLE Companies (Industry VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT Industry) FROM Companies [/SQL]


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

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

Answer: [SQL] SELECT name FROM buildings ORDER BY Height DESC [/SQL]


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

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

Answer: [SQL] SELECT Stories FROM buildings ORDER BY Height DESC LIMIT 1 [/SQL]