Question: Find the last name of the latest contact individual of the organization "Labour Party".

Context: CREATE TABLE organizations (organization_id VARCHAR, organization_name VARCHAR); CREATE TABLE individuals (individual_last_name VARCHAR, individual_id VARCHAR); CREATE TABLE organization_contact_individuals (organization_id VARCHAR, individual_id VARCHAR, date_contact_to VARCHAR)

Answer: [SQL] SELECT t3.individual_last_name FROM organizations AS t1 JOIN organization_contact_individuals AS t2 ON t1.organization_id = t2.organization_id JOIN individuals AS t3 ON t2.individual_id = t3.individual_id WHERE t1.organization_name = "Labour Party" ORDER BY t2.date_contact_to DESC LIMIT 1 [/SQL]


Question: Find the last name of the first ever contact person of the organization with the highest UK Vat number.

Context: CREATE TABLE organizations (uk_vat_number INTEGER); CREATE TABLE individuals (individual_last_name VARCHAR, individual_id VARCHAR); CREATE TABLE organizations (organization_id VARCHAR, uk_vat_number INTEGER); CREATE TABLE organization_contact_individuals (organization_id VARCHAR, individual_id VARCHAR, date_contact_to VARCHAR)

Answer: [SQL] SELECT t3.individual_last_name FROM organizations AS t1 JOIN organization_contact_individuals AS t2 ON t1.organization_id = t2.organization_id JOIN individuals AS t3 ON t2.individual_id = t3.individual_id WHERE t1.uk_vat_number = (SELECT MAX(uk_vat_number) FROM organizations) ORDER BY t2.date_contact_to LIMIT 1 [/SQL]


Question: Find name of the services that has never been used.

Context: CREATE TABLE services (service_name VARCHAR); CREATE TABLE party_services (service_id VARCHAR); CREATE TABLE services (service_name VARCHAR, service_id VARCHAR)

Answer: [SQL] SELECT service_name FROM services EXCEPT SELECT t1.service_name FROM services AS t1 JOIN party_services AS t2 ON t1.service_id = t2.service_id [/SQL]


Question: Find the name of all the cities and states.

Context: CREATE TABLE addresses (town_city VARCHAR, state_province_county VARCHAR)

Answer: [SQL] SELECT town_city FROM addresses UNION SELECT state_province_county FROM addresses [/SQL]


Question: How many cities are there in state "Colorado"?

Context: CREATE TABLE addresses (state_province_county VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM addresses WHERE state_province_county = "Colorado" [/SQL]


Question: Find the payment method code used by more than 3 parties.

Context: CREATE TABLE parties (payment_method_code VARCHAR)

Answer: [SQL] SELECT payment_method_code FROM parties GROUP BY payment_method_code HAVING COUNT(*) > 3 [/SQL]


Question: Find the name of organizations whose names contain "Party".

Context: CREATE TABLE organizations (organization_name VARCHAR)

Answer: [SQL] SELECT organization_name FROM organizations WHERE organization_name LIKE "%Party%" [/SQL]


Question: How many distinct payment methods are used by parties?

Answer: [SQL] SELECT COUNT(DISTINCT payment_method_code) FROM parties [/SQL]


Question: Which is the email of the party that has used the services the most number of times?

Context: CREATE TABLE parties (party_email VARCHAR, party_id VARCHAR); CREATE TABLE party_services (customer_id VARCHAR)

Answer: [SQL] SELECT t1.party_email FROM parties AS t1 JOIN party_services AS t2 ON t1.party_id = t2.customer_id GROUP BY t1.party_email ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Which state can address "6862 Kaitlyn Knolls" possibly be in?

Context: CREATE TABLE addresses (state_province_county VARCHAR, line_1_number_building VARCHAR)

Answer: [SQL] SELECT state_province_county FROM addresses WHERE line_1_number_building LIKE "%6862 Kaitlyn Knolls%" [/SQL]


Question: What is the name of organization that has the greatest number of contact individuals?

Context: CREATE TABLE organization_contact_individuals (organization_id VARCHAR); CREATE TABLE organizations (organization_name VARCHAR, organization_id VARCHAR)

Answer: [SQL] SELECT t1.organization_name FROM organizations AS t1 JOIN organization_contact_individuals AS t2 ON t1.organization_id = t2.organization_id GROUP BY t1.organization_name ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the last name of the individuals that have been contact individuals of an organization.

Context: CREATE TABLE individuals (individual_last_name VARCHAR, individual_id VARCHAR); CREATE TABLE organization_contact_individuals (individual_id VARCHAR)

Answer: [SQL] SELECT DISTINCT t1.individual_last_name FROM individuals AS t1 JOIN organization_contact_individuals AS t2 ON t1.individual_id = t2.individual_id [/SQL]


Question: How many drivers are there?

Context: CREATE TABLE driver (Id VARCHAR)

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


Question: Show the name, home city, and age for all drivers.

Context: CREATE TABLE driver (name VARCHAR, home_city VARCHAR, age VARCHAR)

Answer: [SQL] SELECT name, home_city, age FROM driver [/SQL]


Question: Show the party and the number of drivers in each party.

Context: CREATE TABLE driver (party VARCHAR)

Answer: [SQL] SELECT party, COUNT(*) FROM driver GROUP BY party [/SQL]


Question: Show the name of drivers in descending order of age.

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

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


Question: Show all different home cities.

Context: CREATE TABLE driver (home_city VARCHAR)

Answer: [SQL] SELECT DISTINCT home_city FROM driver [/SQL]


Question: Show the home city with the most number of drivers.

Context: CREATE TABLE driver (home_city VARCHAR)

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


Question: Show the party with drivers from Hartford and drivers older than 40.

Context: CREATE TABLE driver (party VARCHAR, home_city VARCHAR, age VARCHAR)

Answer: [SQL] SELECT party FROM driver WHERE home_city = 'Hartford' AND age > 40 [/SQL]


Question: Show home city where at least two drivers older than 40 are from.

Context: CREATE TABLE driver (home_city VARCHAR, age INTEGER)

Answer: [SQL] SELECT home_city FROM driver WHERE age > 40 GROUP BY home_city HAVING COUNT(*) >= 2 [/SQL]


Question: Show all home cities except for those having a driver older than 40.

Answer: [SQL] SELECT home_city FROM driver EXCEPT SELECT home_city FROM driver WHERE age > 40 [/SQL]


Question: Show the names of the drivers without a school bus.

Context: CREATE TABLE school_bus (name VARCHAR, driver_id VARCHAR); CREATE TABLE driver (name VARCHAR, driver_id VARCHAR)

Answer: [SQL] SELECT name FROM driver WHERE NOT driver_id IN (SELECT driver_id FROM school_bus) [/SQL]


Question: Show the types of schools that have two schools.

Context: CREATE TABLE school (TYPE VARCHAR)

Answer: [SQL] SELECT TYPE FROM school GROUP BY TYPE HAVING COUNT(*) = 2 [/SQL]


Question: Show the school name and driver name for all school buses.

Context: CREATE TABLE school (school VARCHAR, school_id VARCHAR); CREATE TABLE school_bus (school_id VARCHAR, driver_id VARCHAR); CREATE TABLE driver (name VARCHAR, driver_id VARCHAR)

Answer: [SQL] SELECT T2.school, T3.name FROM school_bus AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id JOIN driver AS T3 ON T1.driver_id = T3.driver_id [/SQL]


Question: What is the maximum, minimum and average years spent working on a school bus?

Context: CREATE TABLE school_bus (years_working INTEGER)

Answer: [SQL] SELECT MAX(years_working), MIN(years_working), AVG(years_working) FROM school_bus [/SQL]


Question: Show the school name and type for schools without a school bus.

Context: CREATE TABLE school_bus (school VARCHAR, TYPE VARCHAR, school_id VARCHAR); CREATE TABLE school (school VARCHAR, TYPE VARCHAR, school_id VARCHAR)

Answer: [SQL] SELECT school, TYPE FROM school WHERE NOT school_id IN (SELECT school_id FROM school_bus) [/SQL]


Question: Show the type of school and the number of buses for each type.

Context: CREATE TABLE school (type VARCHAR, school_id VARCHAR); CREATE TABLE school_bus (school_id VARCHAR)

Answer: [SQL] SELECT T2.type, COUNT(*) FROM school_bus AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id GROUP BY T2.type [/SQL]


Question: How many drivers are from Hartford city or younger than 40?

Context: CREATE TABLE driver (home_city VARCHAR, age VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM driver WHERE home_city = 'Hartford' OR age < 40 [/SQL]


Question: List names for drivers from Hartford city and younger than 40.

Answer: [SQL] SELECT name FROM driver WHERE home_city = 'Hartford' AND age < 40 [/SQL]


Question: find the name of driver who is driving the school bus with the longest working history.

Context: CREATE TABLE school_bus (driver_id VARCHAR); CREATE TABLE driver (name VARCHAR, driver_id VARCHAR)

Answer: [SQL] SELECT t1.name FROM driver AS t1 JOIN school_bus AS t2 ON t1.driver_id = t2.driver_id ORDER BY years_working DESC LIMIT 1 [/SQL]


Question: How many flights have a velocity larger than 200?

Context: CREATE TABLE flight (velocity INTEGER)

Answer: [SQL] SELECT COUNT(*) FROM flight WHERE velocity > 200 [/SQL]


Question: List the vehicle flight number, date and pilot of all the flights, ordered by altitude.

Context: CREATE TABLE flight (vehicle_flight_number VARCHAR, date VARCHAR, pilot VARCHAR, altitude VARCHAR)

Answer: [SQL] SELECT vehicle_flight_number, date, pilot FROM flight ORDER BY altitude [/SQL]


Question: List the id, country, city and name of the airports ordered alphabetically by the name.

Context: CREATE TABLE airport (id VARCHAR, country VARCHAR, city VARCHAR, name VARCHAR)

Answer: [SQL] SELECT id, country, city, name FROM airport ORDER BY name [/SQL]


Question: What is maximum group equity shareholding of the companies?

Context: CREATE TABLE operate_company (group_equity_shareholding INTEGER)

Answer: [SQL] SELECT MAX(group_equity_shareholding) FROM operate_company [/SQL]


Question: What is the velocity of the pilot named 'Thompson'?

Context: CREATE TABLE flight (velocity INTEGER, pilot VARCHAR)

Answer: [SQL] SELECT AVG(velocity) FROM flight WHERE pilot = 'Thompson' [/SQL]


Question: What are the names and types of the companies that have ever operated a flight?

Context: CREATE TABLE operate_company (name VARCHAR, type VARCHAR, id VARCHAR); CREATE TABLE flight (Id VARCHAR)

Answer: [SQL] SELECT T1.name, T1.type FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id [/SQL]


Question: What are the names of the airports which are not in the country 'Iceland'?

Context: CREATE TABLE airport (name VARCHAR, country VARCHAR)

Answer: [SQL] SELECT name FROM airport WHERE country <> 'Iceland' [/SQL]


Question: What are the distinct types of the companies that have operated any flights with velocity less than 200?

Context: CREATE TABLE flight (Id VARCHAR); CREATE TABLE operate_company (type VARCHAR, id VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.type FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id WHERE T2.velocity < 200 [/SQL]


Question: What are the ids and names of the companies that operated more than one flight?

Context: CREATE TABLE flight (Id VARCHAR); CREATE TABLE operate_company (id VARCHAR, name VARCHAR)

Answer: [SQL] SELECT T1.id, T1.name FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id GROUP BY T1.id HAVING COUNT(*) > 1 [/SQL]


Question: What is the id, name and IATA code of the airport that had most number of flights?

Context: CREATE TABLE airport (id VARCHAR, name VARCHAR, IATA VARCHAR); CREATE TABLE flight (id VARCHAR, airport_id VARCHAR)

Answer: [SQL] SELECT T1.id, T1.name, T1.IATA FROM airport AS T1 JOIN flight AS T2 ON T1.id = T2.airport_id GROUP BY T2.id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What are the different pilot names who had piloted a flight in the country 'United States' or in the airport named 'Billund Airport'?

Context: CREATE TABLE airport (id VARCHAR, country VARCHAR, name VARCHAR); CREATE TABLE flight (pilot VARCHAR, airport_id VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.pilot FROM airport AS T1 JOIN flight AS T2 ON T1.id = T2.airport_id WHERE T1.country = 'United States' OR T1.name = 'Billund Airport' [/SQL]


Question: What is the most common company type, and how many are there?

Context: CREATE TABLE operate_company (TYPE VARCHAR)

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


Question: How many airports haven't the pilot 'Thompson' driven an aircraft?

Context: CREATE TABLE airport (id VARCHAR, airport_id VARCHAR, pilot VARCHAR); CREATE TABLE flight (id VARCHAR, airport_id VARCHAR, pilot VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM airport WHERE NOT id IN (SELECT airport_id FROM flight WHERE pilot = 'Thompson') [/SQL]


Question: List the name of the pilots who have flied for both a company that mainly provide 'Cargo' services and a company that runs 'Catering services' activities.

Context: CREATE TABLE operate_company (id VARCHAR, principal_activities VARCHAR); CREATE TABLE flight (Id VARCHAR)

Answer: [SQL] SELECT T2.pilot FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id WHERE T1.principal_activities = 'Cargo' INTERSECT SELECT T2.pilot FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id WHERE T1.principal_activities = 'Catering services' [/SQL]


Question: Which of the airport names contains the word 'international'?

Context: CREATE TABLE airport (name VARCHAR)

Answer: [SQL] SELECT name FROM airport WHERE name LIKE '%international%' [/SQL]


Question: How many companies operates airlines in each airport?

Context: CREATE TABLE airport (id VARCHAR); CREATE TABLE flight (Id VARCHAR); CREATE TABLE operate_company (id VARCHAR)

Answer: [SQL] SELECT T3.id, COUNT(*) FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id JOIN airport AS T3 ON T2.airport_id = T3.id GROUP BY T3.id [/SQL]


Question: how many airports are there in each country?

Context: CREATE TABLE airport (country VARCHAR)

Answer: [SQL] SELECT COUNT(*), country FROM airport GROUP BY country [/SQL]


Question: which countries have more than 2 airports?

Context: CREATE TABLE airport (country VARCHAR)

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


Question: which pilot is in charge of the most number of flights?

Context: CREATE TABLE flight (pilot VARCHAR)

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


Question: Show all account ids and account details.

Context: CREATE TABLE Accounts (account_id VARCHAR, account_details VARCHAR)

Answer: [SQL] SELECT account_id, account_details FROM Accounts [/SQL]


Question: How many statements do we have?

Context: CREATE TABLE Statements (Id VARCHAR)

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


Question: List all statement ids and statement details.

Context: CREATE TABLE Statements (STATEMENT_ID VARCHAR, statement_details VARCHAR)

Answer: [SQL] SELECT STATEMENT_ID, statement_details FROM Statements [/SQL]


Question: Show statement id, statement detail, account detail for accounts.

Context: CREATE TABLE Accounts (statement_id VARCHAR, account_details VARCHAR); CREATE TABLE Statements (statement_details VARCHAR, statement_id VARCHAR)

Answer: [SQL] SELECT T1.statement_id, T2.statement_details, T1.account_details FROM Accounts AS T1 JOIN Statements AS T2 ON T1.statement_id = T2.statement_id [/SQL]


Question: Show all statement id and the number of accounts for each statement.

Context: CREATE TABLE Accounts (STATEMENT_ID VARCHAR)

Answer: [SQL] SELECT STATEMENT_ID, COUNT(*) FROM Accounts GROUP BY STATEMENT_ID [/SQL]


Question: Show the statement id and the statement detail for the statement with most number of accounts.

Context: CREATE TABLE Accounts (statement_id VARCHAR); CREATE TABLE Statements (statement_details VARCHAR, statement_id VARCHAR)

Answer: [SQL] SELECT T1.statement_id, T2.statement_details FROM Accounts AS T1 JOIN Statements AS T2 ON T1.statement_id = T2.statement_id GROUP BY T1.statement_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the number of documents.

Context: CREATE TABLE Documents (Id VARCHAR)

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


Question: List the document type code, document name, and document description for the document with name 'Noel CV' or name 'King Book'.

Context: CREATE TABLE Documents (document_type_code VARCHAR, document_name VARCHAR, document_description VARCHAR)

Answer: [SQL] SELECT document_type_code, document_name, document_description FROM Documents WHERE document_name = 'Noel CV' OR document_name = 'King Book' [/SQL]


Question: Show the ids and names of all documents.

Context: CREATE TABLE Documents (document_id VARCHAR, document_name VARCHAR)

Answer: [SQL] SELECT document_id, document_name FROM Documents [/SQL]


Question: Find names and ids of all documents with document type code BK.

Context: CREATE TABLE Documents (document_name VARCHAR, document_id VARCHAR, document_type_code VARCHAR)

Answer: [SQL] SELECT document_name, document_id FROM Documents WHERE document_type_code = "BK" [/SQL]


Question: How many documents are with document type code BK for each product id?

Context: CREATE TABLE Documents (project_id VARCHAR, document_type_code VARCHAR)

Answer: [SQL] SELECT COUNT(*), project_id FROM Documents WHERE document_type_code = "BK" GROUP BY project_id [/SQL]


Question: Show the document name and the document date for all documents on project with details 'Graph Database project'.

Context: CREATE TABLE Documents (project_id VARCHAR); CREATE TABLE projects (project_id VARCHAR, project_details VARCHAR)

Answer: [SQL] SELECT document_name, document_date FROM Documents AS T1 JOIN projects AS T2 ON T1.project_id = T2.project_id WHERE T2.project_details = 'Graph Database project' [/SQL]


Question: Show project ids and the number of documents in each project.

Context: CREATE TABLE Documents (project_id VARCHAR)

Answer: [SQL] SELECT project_id, COUNT(*) FROM Documents GROUP BY project_id [/SQL]


Question: What is the id of the project with least number of documents?

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


Question: Show the ids for projects with at least 2 documents.

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


Question: List document type codes and the number of documents in each code.

Context: CREATE TABLE Documents (document_type_code VARCHAR)

Answer: [SQL] SELECT document_type_code, COUNT(*) FROM Documents GROUP BY document_type_code [/SQL]


Question: What is the document type code with most number of documents?

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


Question: Show the document type code with fewer than 3 documents.

Answer: [SQL] SELECT document_type_code FROM Documents GROUP BY document_type_code HAVING COUNT(*) < 3 [/SQL]


Question: Show the statement detail and the corresponding document name for the statement with detail 'Private Project'.

Context: CREATE TABLE Statements (statement_details VARCHAR, statement_id VARCHAR); CREATE TABLE Documents (document_name VARCHAR, document_id VARCHAR)

Answer: [SQL] SELECT T1.statement_details, T2.document_name FROM Statements AS T1 JOIN Documents AS T2 ON T1.statement_id = T2.document_id WHERE T1.statement_details = 'Private Project' [/SQL]


Question: Show all document type codes, document type names, document type descriptions.

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

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


Question: What is the document type description for document type named Film?

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

Answer: [SQL] SELECT document_type_description FROM Ref_document_types WHERE document_type_name = "Film" [/SQL]


Question: What is the document type name and the document type description and creation date for all the documents?

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

Answer: [SQL] SELECT T1.document_type_name, T1.document_type_description, T2.Document_date FROM Ref_document_types AS T1 JOIN Documents AS T2 ON T1.document_type_code = T2.document_type_code [/SQL]


Question: Show the number of projects.

Context: CREATE TABLE Projects (Id VARCHAR)

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


Question: List ids and details for all projects.

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

Answer: [SQL] SELECT project_id, project_details FROM Projects [/SQL]


Question: What is the project id and detail for the project with at least two documents?

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

Answer: [SQL] SELECT T1.project_id, T1.project_details FROM Projects AS T1 JOIN Documents AS T2 ON T1.project_id = T2.project_id GROUP BY T1.project_id HAVING COUNT(*) > 2 [/SQL]


Question: What is the project detail for the project with document "King Book"?

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

Answer: [SQL] SELECT T1.project_details FROM Projects AS T1 JOIN Documents AS T2 ON T1.project_id = T2.project_id WHERE T2.document_name = "King Book" [/SQL]


Question: How many budget types do we have?

Context: CREATE TABLE Ref_budget_codes (Id VARCHAR)

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


Question: List all budget type codes and descriptions.

Context: CREATE TABLE Ref_budget_codes (budget_type_code VARCHAR, budget_type_description VARCHAR)

Answer: [SQL] SELECT budget_type_code, budget_type_description FROM Ref_budget_codes [/SQL]


Question: What is the description for the budget type with code ORG?

Context: CREATE TABLE Ref_budget_codes (budget_type_description VARCHAR, budget_type_code VARCHAR)

Answer: [SQL] SELECT budget_type_description FROM Ref_budget_codes WHERE budget_type_code = "ORG" [/SQL]


Question: How many documents have expenses?

Context: CREATE TABLE Documents_with_expenses (Id VARCHAR)

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


Question: What are the document ids for the budget type code 'SF'?

Context: CREATE TABLE Documents_with_expenses (document_id VARCHAR, budget_type_code VARCHAR)

Answer: [SQL] SELECT document_id FROM Documents_with_expenses WHERE budget_type_code = 'SF' [/SQL]


Question: Show the budget type code and description and the corresponding document id.

Context: CREATE TABLE Ref_budget_codes (budget_type_code VARCHAR, budget_type_description VARCHAR); CREATE TABLE Documents_with_expenses (document_id VARCHAR, budget_type_code VARCHAR)

Answer: [SQL] SELECT T2.budget_type_code, T2.budget_type_description, T1.document_id FROM Documents_with_expenses AS T1 JOIN Ref_budget_codes AS T2 ON T1.budget_type_code = T2.budget_type_code [/SQL]


Question: Show ids for all documents with budget types described as 'Government'.

Context: CREATE TABLE Documents_with_expenses (document_id VARCHAR, Budget_Type_code VARCHAR); CREATE TABLE Ref_Budget_Codes (Budget_Type_code VARCHAR, budget_type_Description VARCHAR)

Answer: [SQL] SELECT T1.document_id FROM Documents_with_expenses AS T1 JOIN Ref_Budget_Codes AS T2 ON T1.Budget_Type_code = T2.Budget_Type_code WHERE T2.budget_type_Description = "Government" [/SQL]


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

Context: CREATE TABLE Documents_with_expenses (budget_type_code VARCHAR)

Answer: [SQL] SELECT budget_type_code, COUNT(*) FROM Documents_with_expenses GROUP BY budget_type_code [/SQL]


Question: What is the budget type code with most number of documents.

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


Question: What are the ids of documents which don't have expense budgets?

Context: CREATE TABLE Documents (document_id VARCHAR); CREATE TABLE Documents_with_expenses (document_id VARCHAR)

Answer: [SQL] SELECT document_id FROM Documents EXCEPT SELECT document_id FROM Documents_with_expenses [/SQL]


Question: Show ids for all documents in type CV without expense budgets.

Context: CREATE TABLE Documents_with_expenses (document_id VARCHAR, document_type_code VARCHAR); CREATE TABLE Documents (document_id VARCHAR, document_type_code VARCHAR)

Answer: [SQL] SELECT document_id FROM Documents WHERE document_type_code = "CV" EXCEPT SELECT document_id FROM Documents_with_expenses [/SQL]


Question: What are the ids of documents with letter 's' in the name with any expense budgets.

Context: CREATE TABLE Documents_with_expenses (document_id VARCHAR); CREATE TABLE Documents (document_id VARCHAR, document_name VARCHAR)

Answer: [SQL] SELECT T1.document_id FROM Documents AS T1 JOIN Documents_with_expenses AS T2 ON T1.document_id = T2.document_id WHERE T1.document_name LIKE '%s%' [/SQL]


Question: How many documents do not have any expense?

Answer: [SQL] SELECT COUNT(*) FROM Documents WHERE NOT document_id IN (SELECT document_id FROM Documents_with_expenses) [/SQL]


Question: What are the dates for the documents with both 'GV' type and 'SF' type expenses?

Context: CREATE TABLE Documents_with_Expenses (document_id VARCHAR, budget_type_code VARCHAR); CREATE TABLE Documents (document_date VARCHAR, document_id VARCHAR)

Answer: [SQL] SELECT T1.document_date FROM Documents AS T1 JOIN Documents_with_Expenses AS T2 ON T1.document_id = T2.document_id WHERE T2.budget_type_code = 'GV' INTERSECT SELECT T1.document_date FROM Documents AS T1 JOIN Documents_with_Expenses AS T2 ON T1.document_id = T2.document_id WHERE T2.budget_type_code = 'SF' [/SQL]


Question: What are the account details with the largest value or with value having char '5' in it?

Context: CREATE TABLE Accounts (Account_details INTEGER)

Answer: [SQL] SELECT MAX(Account_details) FROM Accounts UNION SELECT Account_details FROM Accounts WHERE Account_details LIKE "%5%" [/SQL]


Question: Find the total number of scientists.

Context: CREATE TABLE scientists (Id VARCHAR)

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


Question: Find the total hours of all projects.

Context: CREATE TABLE projects (hours INTEGER)

Answer: [SQL] SELECT SUM(hours) FROM projects [/SQL]


Question: How many different scientists are assigned to any project?

Context: CREATE TABLE assignedto (scientist VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT scientist) FROM assignedto [/SQL]


Question: Find the number of distinct projects.

Context: CREATE TABLE projects (name VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT name) FROM projects [/SQL]


Question: Find the average hours of all projects.

Context: CREATE TABLE projects (hours INTEGER)

Answer: [SQL] SELECT AVG(hours) FROM projects [/SQL]


Question: Find the name of project that continues for the longest time.

Context: CREATE TABLE projects (name VARCHAR, hours VARCHAR)

Answer: [SQL] SELECT name FROM projects ORDER BY hours DESC LIMIT 1 [/SQL]


Question: List the name of all projects that are operated longer than the average working hours of all projects.

Context: CREATE TABLE projects (name VARCHAR, hours INTEGER)

Answer: [SQL] SELECT name FROM projects WHERE hours > (SELECT AVG(hours) FROM projects) [/SQL]


Question: Find the name and hours of project that has the most number of scientists.

Context: CREATE TABLE assignedto (project VARCHAR); CREATE TABLE projects (name VARCHAR, hours VARCHAR, code VARCHAR)

Answer: [SQL] SELECT T1.name, T1.hours FROM projects AS T1 JOIN assignedto AS T2 ON T1.code = T2.project GROUP BY T2.project ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the name of the project for which a scientist whose name contains ‘Smith’ is assigned to.

Context: CREATE TABLE scientists (SSN VARCHAR, name VARCHAR); CREATE TABLE assignedto (project VARCHAR, scientist VARCHAR); CREATE TABLE projects (name VARCHAR, code VARCHAR)

Answer: [SQL] SELECT T2.name FROM assignedto AS T1 JOIN projects AS T2 ON T1.project = T2.code JOIN scientists AS T3 ON T1.scientist = T3.SSN WHERE T3.name LIKE '%Smith%' [/SQL]


Question: Find the total hours of the projects that scientists named Michael Rogers or Carol Smith are assigned to.

Context: CREATE TABLE scientists (SSN VARCHAR, name VARCHAR); CREATE TABLE projects (hours INTEGER, code VARCHAR); CREATE TABLE assignedto (project VARCHAR, scientist VARCHAR)

Answer: [SQL] SELECT SUM(T2.hours) FROM assignedto AS T1 JOIN projects AS T2 ON T1.project = T2.code JOIN scientists AS T3 ON T1.scientist = T3.SSN WHERE T3.name = 'Michael Rogers' OR T3.name = 'Carol Smith' [/SQL]


Question: Find the name of projects that require between 100 and 300 hours of work.

Answer: [SQL] SELECT name FROM projects WHERE hours BETWEEN 100 AND 300 [/SQL]


Question: Find the name of the scientist who worked on both a project named 'Matter of Time' and a project named 'A Puzzling Parallax'.

Context: CREATE TABLE projects (code VARCHAR, name VARCHAR); CREATE TABLE scientists (name VARCHAR, SSN VARCHAR); CREATE TABLE assignedto (project VARCHAR, scientist VARCHAR)

Answer: [SQL] SELECT T3.name FROM assignedto AS T1 JOIN projects AS T2 ON T1.project = T2.code JOIN scientists AS T3 ON T1.scientist = T3.SSN WHERE T2.name = 'Matter of Time' INTERSECT SELECT T3.name FROM assignedto AS T1 JOIN projects AS T2 ON T1.project = T2.code JOIN scientists AS T3 ON T1.scientist = T3.SSN WHERE T2.name = 'A Puzzling Parallax' [/SQL]


Question: List the names of all scientists sorted in alphabetical order.

Context: CREATE TABLE scientists (name VARCHAR)

Answer: [SQL] SELECT name FROM scientists ORDER BY name [/SQL]


Question: Find the number of scientists involved for each project name.

Context: CREATE TABLE assignedto (project VARCHAR); CREATE TABLE projects (name VARCHAR, code VARCHAR)

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


Question: Find the number of scientists involved for the projects that require more than 300 hours.

Context: CREATE TABLE assignedto (project VARCHAR); CREATE TABLE projects (name VARCHAR, code VARCHAR, hours INTEGER)

Answer: [SQL] SELECT COUNT(*), T1.name FROM projects AS T1 JOIN assignedto AS T2 ON T1.code = T2.project WHERE T1.hours > 300 GROUP BY T1.name [/SQL]


Question: Find the number of projects which each scientist is working on and scientist's name.

Context: CREATE TABLE scientists (name VARCHAR, ssn VARCHAR); CREATE TABLE assignedto (scientist VARCHAR)

Answer: [SQL] SELECT COUNT(*), T1.name FROM scientists AS T1 JOIN assignedto AS T2 ON T1.ssn = T2.scientist GROUP BY T1.name [/SQL]


Question: Find the SSN and name of scientists who are assigned to the project with the longest hours.

Context: CREATE TABLE scientists (ssn VARCHAR, name VARCHAR, SSN VARCHAR); CREATE TABLE projects (code VARCHAR, hours INTEGER); CREATE TABLE assignedto (project VARCHAR, scientist VARCHAR); CREATE TABLE projects (hours INTEGER)

Answer: [SQL] SELECT T3.ssn, T3.name FROM assignedto AS T1 JOIN projects AS T2 ON T1.project = T2.code JOIN scientists AS T3 ON T1.scientist = T3.SSN WHERE T2.hours = (SELECT MAX(hours) FROM projects) [/SQL]


Question: Find the name of scientists who are assigned to some project.

Context: CREATE TABLE assignedto (scientist VARCHAR); CREATE TABLE scientists (name VARCHAR, ssn VARCHAR)

Answer: [SQL] SELECT T2.name FROM assignedto AS T1 JOIN scientists AS T2 ON T1.scientist = T2.ssn [/SQL]


Question: Select the project names which are not assigned yet.

Context: CREATE TABLE Projects (Name VARCHAR, Code VARCHAR, Project VARCHAR); CREATE TABLE AssignedTo (Name VARCHAR, Code VARCHAR, Project VARCHAR)

Answer: [SQL] SELECT Name FROM Projects WHERE NOT Code IN (SELECT Project FROM AssignedTo) [/SQL]


Question: Find the name of scientists who are not assigned to any project.

Context: CREATE TABLE scientists (Name VARCHAR, ssn VARCHAR, scientist VARCHAR); CREATE TABLE AssignedTo (Name VARCHAR, ssn VARCHAR, scientist VARCHAR)

Answer: [SQL] SELECT Name FROM scientists WHERE NOT ssn IN (SELECT scientist FROM AssignedTo) [/SQL]


Question: Find the number of scientists who are not assigned to any project.

Context: CREATE TABLE AssignedTo (ssn VARCHAR, scientist VARCHAR); CREATE TABLE scientists (ssn VARCHAR, scientist VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM scientists WHERE NOT ssn IN (SELECT scientist FROM AssignedTo) [/SQL]


Question: Find the names of scientists who are not working on the project with the highest hours.

Context: CREATE TABLE scientists (name VARCHAR, SSN VARCHAR); CREATE TABLE assignedto (project VARCHAR, scientist VARCHAR); CREATE TABLE projects (code VARCHAR, hours INTEGER); CREATE TABLE scientists (name VARCHAR, hours INTEGER); CREATE TABLE projects (name VARCHAR, hours INTEGER)

Answer: [SQL] SELECT name FROM scientists EXCEPT SELECT T3.name FROM assignedto AS T1 JOIN projects AS T2 ON T1.project = T2.code JOIN scientists AS T3 ON T1.scientist = T3.SSN WHERE T2.hours = (SELECT MAX(hours) FROM projects) [/SQL]


Question: List all the scientists' names, their projects' names, and the hours worked by that scientist on each project, in alphabetical order of project name, and then scientist name.

Context: CREATE TABLE AssignedTo (Scientist VARCHAR, Project VARCHAR); CREATE TABLE Projects (Name VARCHAR, Hours VARCHAR, Code VARCHAR); CREATE TABLE Scientists (Name VARCHAR, SSN VARCHAR)

Answer: [SQL] SELECT T1.Name, T3.Name, T3.Hours FROM Scientists AS T1 JOIN AssignedTo AS T2 ON T1.SSN = T2.Scientist JOIN Projects AS T3 ON T2.Project = T3.Code ORDER BY T3.Name, T1.Name [/SQL]


Question: Find name of the project that needs the least amount of time to finish and the name of scientists who worked on it.

Context: CREATE TABLE scientists (name VARCHAR, SSN VARCHAR); CREATE TABLE assignedto (project VARCHAR, scientist VARCHAR); CREATE TABLE projects (name VARCHAR, code VARCHAR, hours INTEGER); CREATE TABLE projects (hours INTEGER)

Answer: [SQL] SELECT T2.name, T3.name FROM assignedto AS T1 JOIN projects AS T2 ON T1.project = T2.code JOIN scientists AS T3 ON T1.scientist = T3.SSN WHERE T2.hours = (SELECT MIN(hours) FROM projects) [/SQL]


Question: What is the name of the highest rated wine?

Context: CREATE TABLE WINE (Name VARCHAR, Score VARCHAR)

Answer: [SQL] SELECT Name FROM WINE ORDER BY Score LIMIT 1 [/SQL]


Question: Which winery is the wine that has the highest score from?

Context: CREATE TABLE WINE (Winery VARCHAR, SCORE VARCHAR)

Answer: [SQL] SELECT Winery FROM WINE ORDER BY SCORE LIMIT 1 [/SQL]


Question: Find the names of all wines produced in 2008.

Context: CREATE TABLE WINE (Name VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT Name FROM WINE WHERE YEAR = "2008" [/SQL]


Question: List the grapes and appelations of all wines.

Context: CREATE TABLE WINE (Grape VARCHAR, Appelation VARCHAR)

Answer: [SQL] SELECT Grape, Appelation FROM WINE [/SQL]


Question: List the names and scores of all wines.

Answer: [SQL] SELECT Name, Score FROM WINE [/SQL]


Question: List the area and county of all appelations.

Context: CREATE TABLE APPELLATIONS (Area VARCHAR, County VARCHAR)

Answer: [SQL] SELECT Area, County FROM APPELLATIONS [/SQL]


Question: What are the prices of wines produced before the year of 2010?

Context: CREATE TABLE WINE (Price VARCHAR, YEAR INTEGER)

Answer: [SQL] SELECT Price FROM WINE WHERE YEAR < 2010 [/SQL]


Question: List the names of all distinct wines that have scores higher than 90.

Context: CREATE TABLE WINE (Name VARCHAR, score INTEGER)

Answer: [SQL] SELECT Name FROM WINE WHERE score > 90 [/SQL]


Question: List the names of all distinct wines that are made of red color grape.

Context: CREATE TABLE GRAPES (Grape VARCHAR, Color VARCHAR); CREATE TABLE WINE (Name VARCHAR, Grape VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.Name FROM GRAPES AS T1 JOIN WINE AS T2 ON T1.Grape = T2.Grape WHERE T1.Color = "Red" [/SQL]


Question: Find the names of all distinct wines that have appellations in North Coast area.

Context: CREATE TABLE APPELLATIONs (Appelation VARCHAR, Area VARCHAR); CREATE TABLE WINE (Name VARCHAR, Appelation VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.Name FROM APPELLATIONs AS T1 JOIN WINE AS T2 ON T1.Appelation = T2.Appelation WHERE T1.Area = "North Coast" [/SQL]


Question: How many wines are produced at Robert Biale winery?

Context: CREATE TABLE WINE (Winery VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM WINE WHERE Winery = "Robert Biale" [/SQL]


Question: How many appelations are in Napa Country?

Context: CREATE TABLE APPELLATIONS (County VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM APPELLATIONS WHERE County = "Napa" [/SQL]


Question: Give me the average prices of wines that are produced by appelations in Sonoma County.

Context: CREATE TABLE WINE (Price INTEGER, Appelation VARCHAR); CREATE TABLE APPELLATIONS (Appelation VARCHAR, County VARCHAR)

Answer: [SQL] SELECT AVG(T2.Price) FROM APPELLATIONS AS T1 JOIN WINE AS T2 ON T1.Appelation = T2.Appelation WHERE T1.County = "Sonoma" [/SQL]


Question: What are the names and scores of wines that are made of white color grapes?

Context: CREATE TABLE GRAPES (Grape VARCHAR, Color VARCHAR); CREATE TABLE WINE (Name VARCHAR, Score VARCHAR, Grape VARCHAR)

Answer: [SQL] SELECT T2.Name, T2.Score FROM GRAPES AS T1 JOIN WINE AS T2 ON T1.Grape = T2.Grape WHERE T1.Color = "White" [/SQL]


Question: Find the maximum price of wins from the appelations in Central Coast area and produced before the year of 2005.

Context: CREATE TABLE APPELLATIONS (Appelation VARCHAR, Area VARCHAR); CREATE TABLE WINE (Price INTEGER, Appelation VARCHAR, year VARCHAR)

Answer: [SQL] SELECT MAX(T2.Price) FROM APPELLATIONS AS T1 JOIN WINE AS T2 ON T1.Appelation = T2.Appelation WHERE T1.Area = "Central Coast" AND T2.year < 2005 [/SQL]


Question: Find the the grape whose white color grapes are used to produce wines with scores higher than 90.

Context: CREATE TABLE GRAPES (Grape VARCHAR, Color VARCHAR); CREATE TABLE WINE (Grape VARCHAR, score VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.Grape FROM GRAPES AS T1 JOIN WINE AS T2 ON T1.Grape = T2.Grape WHERE T1.Color = "White" AND T2.score > 90 [/SQL]


Question: What are the wines that have prices higher than 50 and made of Red color grapes?

Context: CREATE TABLE WINE (Name VARCHAR, Grape VARCHAR, price VARCHAR); CREATE TABLE Grapes (Grape VARCHAR, Color VARCHAR)

Answer: [SQL] SELECT T2.Name FROM Grapes AS T1 JOIN WINE AS T2 ON T1.Grape = T2.Grape WHERE T1.Color = "Red" AND T2.price > 50 [/SQL]


Question: What are the wines that have prices lower than 50 and have appelations in Monterey county?

Context: CREATE TABLE APPELLATIONS (Appelation VARCHAR, County VARCHAR); CREATE TABLE WINE (Name VARCHAR, Appelation VARCHAR, price VARCHAR)

Answer: [SQL] SELECT T2.Name FROM APPELLATIONS AS T1 JOIN WINE AS T2 ON T1.Appelation = T2.Appelation WHERE T1.County = "Monterey" AND T2.price < 50 [/SQL]


Question: What are the numbers of wines for different grapes?

Context: CREATE TABLE WINE (Grape VARCHAR)

Answer: [SQL] SELECT COUNT(*), Grape FROM WINE GROUP BY Grape [/SQL]


Question: What are the average prices of wines for different years?

Context: CREATE TABLE WINE (YEAR VARCHAR, Price INTEGER)

Answer: [SQL] SELECT AVG(Price), YEAR FROM WINE GROUP BY YEAR [/SQL]


Question: Find the distinct names of all wines that have prices higher than some wines from John Anthony winery.

Context: CREATE TABLE wine (Name VARCHAR, Price INTEGER, Winery VARCHAR); CREATE TABLE WINE (Name VARCHAR, Price INTEGER, Winery VARCHAR)

Answer: [SQL] SELECT DISTINCT Name FROM WINE WHERE Price > (SELECT MIN(Price) FROM wine WHERE Winery = "John Anthony") [/SQL]


Question: List the names of all distinct wines in alphabetical order.

Context: CREATE TABLE WINE (Name VARCHAR)

Answer: [SQL] SELECT DISTINCT Name FROM WINE ORDER BY Name [/SQL]


Question: List the names of all distinct wines ordered by price.

Context: CREATE TABLE WINE (Name VARCHAR, price VARCHAR)

Answer: [SQL] SELECT DISTINCT Name FROM WINE ORDER BY price [/SQL]


Question: What is the area of the appelation that produces the highest number of wines before the year of 2010?

Context: CREATE TABLE WINE (Appelation VARCHAR, year VARCHAR); CREATE TABLE APPELLATIONS (Area VARCHAR, Appelation VARCHAR)

Answer: [SQL] SELECT T1.Area FROM APPELLATIONS AS T1 JOIN WINE AS T2 ON T1.Appelation = T2.Appelation GROUP BY T2.Appelation HAVING T2.year < 2010 ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the color of the grape whose wine products has the highest average price?

Context: CREATE TABLE GRAPES (Color VARCHAR, Grape VARCHAR); CREATE TABLE WINE (Grape VARCHAR)

Answer: [SQL] SELECT T1.Color FROM GRAPES AS T1 JOIN WINE AS T2 ON T1.Grape = T2.Grape GROUP BY T2.Grape ORDER BY AVG(Price) DESC LIMIT 1 [/SQL]


Question: Find the distinct names of wines produced before the year of 2000 or after the year of 2010.

Context: CREATE TABLE WINE (Name VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT DISTINCT Name FROM WINE WHERE YEAR < 2000 OR YEAR > 2010 [/SQL]


Question: Find the distinct winery of wines having price between 50 and 100.

Context: CREATE TABLE WINE (Winery VARCHAR, Price INTEGER)

Answer: [SQL] SELECT DISTINCT Winery FROM WINE WHERE Price BETWEEN 50 AND 100 [/SQL]


Question: What are the average prices and cases of wines produced in the year of 2009 and made of Zinfandel grape?

Context: CREATE TABLE WINE (Price INTEGER, Cases INTEGER, YEAR VARCHAR, Grape VARCHAR)

Answer: [SQL] SELECT AVG(Price), AVG(Cases) FROM WINE WHERE YEAR = 2009 AND Grape = "Zinfandel" [/SQL]


Question: What are the maximum price and score of wines produced by St. Helena appelation?

Context: CREATE TABLE WINE (Price INTEGER, Score INTEGER, Appelation VARCHAR)

Answer: [SQL] SELECT MAX(Price), MAX(Score) FROM WINE WHERE Appelation = "St. Helena" [/SQL]


Question: What are the maximum price and score of wines in each year?

Context: CREATE TABLE WINE (YEAR VARCHAR, Price INTEGER, Score INTEGER)

Answer: [SQL] SELECT MAX(Price), MAX(Score), YEAR FROM WINE GROUP BY YEAR [/SQL]


Question: What are the average price and score of wines grouped by appelation?

Context: CREATE TABLE WINE (Appelation VARCHAR, Price INTEGER, Score INTEGER)

Answer: [SQL] SELECT AVG(Price), AVG(Score), Appelation FROM WINE GROUP BY Appelation [/SQL]


Question: Find the wineries that have at least four wines.

Context: CREATE TABLE WINE (Winery VARCHAR)

Answer: [SQL] SELECT Winery FROM WINE GROUP BY Winery HAVING COUNT(*) >= 4 [/SQL]


Question: Find the country of all appelations who have at most three wines.

Context: CREATE TABLE APPELLATIONS (County VARCHAR, Appelation VARCHAR); CREATE TABLE WINE (Appelation VARCHAR)

Answer: [SQL] SELECT T1.County FROM APPELLATIONS AS T1 JOIN WINE AS T2 ON T1.Appelation = T2.Appelation GROUP BY T2.Appelation HAVING COUNT(*) <= 3 [/SQL]


Question: What are the names of wines whose production year are before the year of all wines by Brander winery?

Context: CREATE TABLE WINE (Name VARCHAR, YEAR INTEGER, Winery VARCHAR)

Answer: [SQL] SELECT Name FROM WINE WHERE YEAR < (SELECT MIN(YEAR) FROM WINE WHERE Winery = "Brander") [/SQL]


Question: What are the names of wines that are more expensive then all wines made in the year 2006?

Context: CREATE TABLE WINE (Name VARCHAR, Price INTEGER, YEAR VARCHAR)

Answer: [SQL] SELECT Name FROM WINE WHERE Price > (SELECT MAX(Price) FROM WINE WHERE YEAR = 2006) [/SQL]


Question: Find the top 3 wineries with the greatest number of wines made of white color grapes.

Context: CREATE TABLE GRAPES (GRAPE VARCHAR, Color VARCHAR); CREATE TABLE WINE (Winery VARCHAR, GRAPE VARCHAR)

Answer: [SQL] SELECT T2.Winery FROM GRAPES AS T1 JOIN WINE AS T2 ON T1.GRAPE = T2.GRAPE WHERE T1.Color = "White" GROUP BY T2.Winery ORDER BY COUNT(*) DESC LIMIT 3 [/SQL]


Question: List the grape, winery and year of the wines whose price is bigger than 100 ordered by year.

Context: CREATE TABLE WINE (Grape VARCHAR, Winery VARCHAR, YEAR VARCHAR, Price INTEGER)

Answer: [SQL] SELECT Grape, Winery, YEAR FROM WINE WHERE Price > 100 ORDER BY YEAR [/SQL]


Question: List the grape, appelation and name of wines whose score is higher than 93 ordered by Name.

Context: CREATE TABLE WINE (Grape VARCHAR, Appelation VARCHAR, Name VARCHAR, Score INTEGER)

Answer: [SQL] SELECT Grape, Appelation, Name FROM WINE WHERE Score > 93 ORDER BY Name [/SQL]


Question: Find the appelations that produce wines after the year of 2008 but not in Central Coast area.

Context: CREATE TABLE WINE (Appelation VARCHAR, YEAR INTEGER, Area VARCHAR); CREATE TABLE APPELLATIONS (Appelation VARCHAR, YEAR INTEGER, Area VARCHAR)

Answer: [SQL] SELECT Appelation FROM WINE WHERE YEAR > 2008 EXCEPT SELECT Appelation FROM APPELLATIONS WHERE Area = "Central Coast" [/SQL]


Question: Find the average price of wines that are not produced from Sonoma county.

Context: CREATE TABLE wine (price INTEGER, Appelation VARCHAR); CREATE TABLE APPELLATIONS (Appelation VARCHAR, County VARCHAR); CREATE TABLE WINE (Appelation VARCHAR)

Answer: [SQL] SELECT AVG(price) FROM wine WHERE NOT Appelation IN (SELECT T1.Appelation FROM APPELLATIONS AS T1 JOIN WINE AS T2 ON T1.Appelation = T2.Appelation WHERE T1.County = 'Sonoma') [/SQL]


Question: Find the county where produces the most number of wines with score higher than 90.

Context: CREATE TABLE WINE (Appelation VARCHAR, Score INTEGER); CREATE TABLE APPELLATIONS (County VARCHAR, Appelation VARCHAR)

Answer: [SQL] SELECT T1.County FROM APPELLATIONS AS T1 JOIN WINE AS T2 ON T1.Appelation = T2.Appelation WHERE T2.Score > 90 GROUP BY T1.County ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: How many train stations are there?

Context: CREATE TABLE station (Id VARCHAR)

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


Question: Show the name, location, and number of platforms for all stations.

Context: CREATE TABLE station (name VARCHAR, LOCATION VARCHAR, number_of_platforms VARCHAR)

Answer: [SQL] SELECT name, LOCATION, number_of_platforms FROM station [/SQL]


Question: What are all locations of train stations?

Context: CREATE TABLE station (LOCATION VARCHAR)

Answer: [SQL] SELECT DISTINCT LOCATION FROM station [/SQL]


Question: Show the names and total passengers for all train stations not in London.

Context: CREATE TABLE station (name VARCHAR, total_passengers VARCHAR, LOCATION VARCHAR)

Answer: [SQL] SELECT name, total_passengers FROM station WHERE LOCATION <> 'London' [/SQL]


Question: Show the names and main services for train stations that have the top three total number of passengers.

Context: CREATE TABLE station (name VARCHAR, main_services VARCHAR, total_passengers VARCHAR)

Answer: [SQL] SELECT name, main_services FROM station ORDER BY total_passengers DESC LIMIT 3 [/SQL]


Question: What is the average and maximum number of total passengers for train stations in London or Glasgow?

Context: CREATE TABLE station (total_passengers INTEGER, LOCATION VARCHAR)

Answer: [SQL] SELECT AVG(total_passengers), MAX(total_passengers) FROM station WHERE LOCATION = 'London' OR LOCATION = 'Glasgow' [/SQL]


Question: Show all locations and the total number of platforms and passengers for all train stations in each location.

Context: CREATE TABLE station (LOCATION VARCHAR, number_of_platforms INTEGER, total_passengers INTEGER)

Answer: [SQL] SELECT LOCATION, SUM(number_of_platforms), SUM(total_passengers) FROM station GROUP BY LOCATION [/SQL]


Question: Show all locations that have train stations with at least 15 platforms and train stations with more than 25 total passengers.

Context: CREATE TABLE station (LOCATION VARCHAR, number_of_platforms VARCHAR, total_passengers VARCHAR)

Answer: [SQL] SELECT DISTINCT LOCATION FROM station WHERE number_of_platforms >= 15 AND total_passengers > 25 [/SQL]


Question: Show all locations which don't have a train station with at least 15 platforms.

Context: CREATE TABLE station (LOCATION VARCHAR, number_of_platforms VARCHAR)

Answer: [SQL] SELECT LOCATION FROM station EXCEPT SELECT LOCATION FROM station WHERE number_of_platforms >= 15 [/SQL]


Question: Show the location with most number of train stations.

Context: CREATE TABLE station (LOCATION VARCHAR)

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


Question: Show the name, time, and service for all trains.

Context: CREATE TABLE train (name VARCHAR, TIME VARCHAR, service VARCHAR)

Answer: [SQL] SELECT name, TIME, service FROM train [/SQL]


Question: Show the number of trains

Context: CREATE TABLE train (Id VARCHAR)

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


Question: Show the name and service for all trains in order by time.

Context: CREATE TABLE train (name VARCHAR, service VARCHAR, TIME VARCHAR)

Answer: [SQL] SELECT name, service FROM train ORDER BY TIME [/SQL]


Question: Show the station name and number of trains in each station.

Context: CREATE TABLE station (name VARCHAR, station_id VARCHAR); CREATE TABLE train_station (station_id VARCHAR)

Answer: [SQL] SELECT T2.name, COUNT(*) FROM train_station AS T1 JOIN station AS T2 ON T1.station_id = T2.station_id GROUP BY T1.station_id [/SQL]


Question: show the train name and station name for each train.

Context: CREATE TABLE station (name VARCHAR, station_id VARCHAR); CREATE TABLE train (name VARCHAR, train_id VARCHAR); CREATE TABLE train_station (station_id VARCHAR, train_id VARCHAR)

Answer: [SQL] SELECT T2.name, T3.name FROM train_station AS T1 JOIN station AS T2 ON T1.station_id = T2.station_id JOIN train AS T3 ON T3.train_id = T1.train_id [/SQL]


Question: Show all train names and times in stations in London in descending order by train time.

Context: CREATE TABLE train_station (station_id VARCHAR, train_id VARCHAR); CREATE TABLE station (station_id VARCHAR, location VARCHAR); CREATE TABLE train (name VARCHAR, time VARCHAR, train_id VARCHAR)

Answer: [SQL] SELECT T3.name, T3.time FROM train_station AS T1 JOIN station AS T2 ON T1.station_id = T2.station_id JOIN train AS T3 ON T3.train_id = T1.train_id WHERE T2.location = 'London' ORDER BY T3.time DESC [/SQL]


Question: Show the station name with greatest number of trains.

Answer: [SQL] SELECT T2.name FROM train_station AS T1 JOIN station AS T2 ON T1.station_id = T2.station_id GROUP BY T1.station_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the station name with at least two trains.

Answer: [SQL] SELECT T2.name FROM train_station AS T1 JOIN station AS T2 ON T1.station_id = T2.station_id GROUP BY T1.station_id HAVING COUNT(*) >= 2 [/SQL]


Question: Show all locations with only 1 station.

Context: CREATE TABLE station (LOCATION VARCHAR)

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


Question: Show station names without any trains.

Context: CREATE TABLE station (name VARCHAR, station_id VARCHAR); CREATE TABLE train_station (name VARCHAR, station_id VARCHAR)

Answer: [SQL] SELECT name FROM station WHERE NOT station_id IN (SELECT station_id FROM train_station) [/SQL]


Question: What are the names of the stations which serve both "Ananthapuri Express" and "Guruvayur Express" trains?

Context: CREATE TABLE station (name VARCHAR, station_id VARCHAR); CREATE TABLE train (train_id VARCHAR, Name VARCHAR); CREATE TABLE train_station (station_id VARCHAR, train_id VARCHAR)

Answer: [SQL] SELECT T2.name FROM train_station AS T1 JOIN station AS T2 ON T1.station_id = T2.station_id JOIN train AS T3 ON T3.train_id = T1.train_id WHERE T3.Name = "Ananthapuri Express" INTERSECT SELECT T2.name FROM train_station AS T1 JOIN station AS T2 ON T1.station_id = T2.station_id JOIN train AS T3 ON T3.train_id = T1.train_id WHERE T3.Name = "Guruvayur Express" [/SQL]


Question: Find the names of the trains that do not pass any station located in London.

Context: CREATE TABLE station (station_id VARCHAR); CREATE TABLE train_station (station_id VARCHAR); CREATE TABLE train_station (train_id VARCHAR, station_id VARCHAR); CREATE TABLE train (name VARCHAR, train_id VARCHAR)

Answer: [SQL] SELECT T2.name FROM train_station AS T1 JOIN train AS T2 ON T1.train_id = T2.train_id WHERE NOT T1.station_id IN (SELECT T4.station_id FROM train_station AS T3 JOIN station AS T4 ON T3.station_id = T4.station_id WHERE t4.location = "London") [/SQL]


Question: List the names and locations of all stations ordered by their yearly entry exit and interchange amounts.

Context: CREATE TABLE station (name VARCHAR, LOCATION VARCHAR, Annual_entry_exit VARCHAR, Annual_interchanges VARCHAR)

Answer: [SQL] SELECT name, LOCATION FROM station ORDER BY Annual_entry_exit, Annual_interchanges [/SQL]


Question: List all vehicle id

Context: CREATE TABLE Vehicles (vehicle_id VARCHAR)

Answer: [SQL] SELECT vehicle_id FROM Vehicles [/SQL]


Question: How many vehicle in total?

Context: CREATE TABLE Vehicles (Id VARCHAR)

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


Question: Show the detail of vehicle with id 1.

Context: CREATE TABLE Vehicles (vehicle_details VARCHAR, vehicle_id VARCHAR)

Answer: [SQL] SELECT vehicle_details FROM Vehicles WHERE vehicle_id = 1 [/SQL]


Question: List the first name middle name and last name of all staff.

Context: CREATE TABLE Staff (first_name VARCHAR, middle_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT first_name, middle_name, last_name FROM Staff [/SQL]


Question: What is the birthday of the staff member with first name as Janessa and last name as Sawayn?

Context: CREATE TABLE Staff (date_of_birth VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT date_of_birth FROM Staff WHERE first_name = "Janessa" AND last_name = "Sawayn" [/SQL]


Question: When did the staff member with first name as Janessa and last name as Sawayn join the company?

Context: CREATE TABLE Staff (date_joined_staff VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT date_joined_staff FROM Staff WHERE first_name = "Janessa" AND last_name = "Sawayn" [/SQL]


Question: When did the staff member with first name as Janessa and last name as Sawayn leave the company?

Context: CREATE TABLE Staff (date_left_staff VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT date_left_staff FROM Staff WHERE first_name = "Janessa" AND last_name = "Sawayn" [/SQL]


Question: How many staff have the first name Ludie?

Context: CREATE TABLE Staff (first_name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Staff WHERE first_name = "Ludie" [/SQL]


Question: What is the nickname of staff with first name as Janessa and last name as Sawayn?

Context: CREATE TABLE Staff (nickname VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT nickname FROM Staff WHERE first_name = "Janessa" AND last_name = "Sawayn" [/SQL]


Question: How many staff in total?

Context: CREATE TABLE Staff (Id VARCHAR)

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


Question: Which city does staff with first name as Janessa and last name as Sawayn live?

Context: CREATE TABLE Staff (staff_address_id VARCHAR, first_name VARCHAR, last_name VARCHAR); CREATE TABLE Addresses (city VARCHAR, address_id VARCHAR)

Answer: [SQL] SELECT T1.city FROM Addresses AS T1 JOIN Staff AS T2 ON T1.address_id = T2.staff_address_id WHERE T2.first_name = "Janessa" AND T2.last_name = "Sawayn" [/SQL]


Question: Which country and state does staff with first name as Janessa and last name as Sawayn lived?

Context: CREATE TABLE Addresses (country VARCHAR, state_province_county VARCHAR, address_id VARCHAR); CREATE TABLE Staff (staff_address_id VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT T1.country, T1.state_province_county FROM Addresses AS T1 JOIN Staff AS T2 ON T1.address_id = T2.staff_address_id WHERE T2.first_name = "Janessa" AND T2.last_name = "Sawayn" [/SQL]


Question: How long is the total lesson time took by customer with first name as Rylan and last name as Goodwin?

Context: CREATE TABLE Lessons (lesson_time INTEGER, customer_id VARCHAR); CREATE TABLE Customers (customer_id VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT SUM(T1.lesson_time) FROM Lessons AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.first_name = "Rylan" AND T2.last_name = "Goodwin" [/SQL]


Question: What is the zip code of staff with first name as Janessa and last name as Sawayn lived?

Context: CREATE TABLE Addresses (zip_postcode VARCHAR, address_id VARCHAR); CREATE TABLE Staff (staff_address_id VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT T1.zip_postcode FROM Addresses AS T1 JOIN Staff AS T2 ON T1.address_id = T2.staff_address_id WHERE T2.first_name = "Janessa" AND T2.last_name = "Sawayn" [/SQL]


Question: How many staff live in state Georgia?

Context: CREATE TABLE Addresses (state_province_county VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Addresses WHERE state_province_county = "Georgia" [/SQL]


Question: Find out the first name and last name of staff lived in city Damianfort.

Context: CREATE TABLE Staff (first_name VARCHAR, last_name VARCHAR, staff_address_id VARCHAR); CREATE TABLE Addresses (address_id VARCHAR, city VARCHAR)

Answer: [SQL] SELECT T2.first_name, T2.last_name FROM Addresses AS T1 JOIN Staff AS T2 ON T1.address_id = T2.staff_address_id WHERE T1.city = "Damianfort" [/SQL]


Question: Which city lives most of staffs? List the city name and number of staffs.

Context: CREATE TABLE Staff (staff_address_id VARCHAR); CREATE TABLE Addresses (city VARCHAR, address_id VARCHAR)

Answer: [SQL] SELECT T1.city, COUNT(*) FROM Addresses AS T1 JOIN Staff AS T2 ON T1.address_id = T2.staff_address_id GROUP BY T1.city ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: List the states which have between 2 to 4 staffs living there.

Context: CREATE TABLE Addresses (state_province_county VARCHAR, address_id VARCHAR); CREATE TABLE Staff (staff_address_id VARCHAR)

Answer: [SQL] SELECT T1.state_province_county FROM Addresses AS T1 JOIN Staff AS T2 ON T1.address_id = T2.staff_address_id GROUP BY T1.state_province_county HAVING COUNT(*) BETWEEN 2 AND 4 [/SQL]


Question: List the first name and last name of all customers.

Context: CREATE TABLE Customers (first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT first_name, last_name FROM Customers [/SQL]


Question: List email address and birthday of customer whose first name as Carole.

Context: CREATE TABLE Customers (email_address VARCHAR, date_of_birth VARCHAR, first_name VARCHAR)

Answer: [SQL] SELECT email_address, date_of_birth FROM Customers WHERE first_name = "Carole" [/SQL]


Question: List phone number and email address of customer with more than 2000 outstanding balance.

Context: CREATE TABLE Customers (phone_number VARCHAR, email_address VARCHAR, amount_outstanding INTEGER)

Answer: [SQL] SELECT phone_number, email_address FROM Customers WHERE amount_outstanding > 2000 [/SQL]


Question: What is the status code, mobile phone number and email address of customer with last name as Kohler or first name as Marina?

Context: CREATE TABLE Customers (customer_status_code VARCHAR, cell_mobile_phone_number VARCHAR, email_address VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT customer_status_code, cell_mobile_phone_number, email_address FROM Customers WHERE first_name = "Marina" OR last_name = "Kohler" [/SQL]


Question: When are the birthdays of customer who are classified as 'Good Customer' status?

Context: CREATE TABLE Customers (date_of_birth VARCHAR, customer_status_code VARCHAR)

Answer: [SQL] SELECT date_of_birth FROM Customers WHERE customer_status_code = 'Good Customer' [/SQL]


Question: When did customer with first name as Carole and last name as Bernhard became a customer?

Context: CREATE TABLE Customers (date_became_customer VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT date_became_customer FROM Customers WHERE first_name = "Carole" AND last_name = "Bernhard" [/SQL]


Question: List all customer status codes and the number of customers having each status code.

Context: CREATE TABLE Customers (customer_status_code VARCHAR)

Answer: [SQL] SELECT customer_status_code, COUNT(*) FROM Customers GROUP BY customer_status_code [/SQL]


Question: Which customer status code has least number of customers?

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


Question: How many lessons taken by customer with first name as Rylan and last name as Goodwin were completed?

Context: CREATE TABLE Lessons (customer_id VARCHAR, lesson_status_code VARCHAR); CREATE TABLE Customers (customer_id VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Lessons AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.first_name = "Rylan" AND T2.last_name = "Goodwin" AND T1.lesson_status_code = "Completed" [/SQL]


Question: What is maximum, minimum and average amount of outstanding of customer?

Context: CREATE TABLE Customers (amount_outstanding INTEGER)

Answer: [SQL] SELECT MAX(amount_outstanding), MIN(amount_outstanding), AVG(amount_outstanding) FROM Customers [/SQL]


Question: List the first name and last name of customers have the amount of outstanding between 1000 and 3000.

Context: CREATE TABLE Customers (first_name VARCHAR, last_name VARCHAR, amount_outstanding INTEGER)

Answer: [SQL] SELECT first_name, last_name FROM Customers WHERE amount_outstanding BETWEEN 1000 AND 3000 [/SQL]


Question: List first name and last name of customers lived in city Lockmanfurt.

Context: CREATE TABLE Customers (first_name VARCHAR, last_name VARCHAR, customer_address_id VARCHAR); CREATE TABLE Addresses (address_id VARCHAR, city VARCHAR)

Answer: [SQL] SELECT T1.first_name, T1.last_name FROM Customers AS T1 JOIN Addresses AS T2 ON T1.customer_address_id = T2.address_id WHERE T2.city = "Lockmanfurt" [/SQL]


Question: Which country does customer with first name as Carole and last name as Bernhard lived in?

Context: CREATE TABLE Addresses (country VARCHAR, address_id VARCHAR); CREATE TABLE Customers (customer_address_id VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT T2.country FROM Customers AS T1 JOIN Addresses AS T2 ON T1.customer_address_id = T2.address_id WHERE T1.first_name = "Carole" AND T1.last_name = "Bernhard" [/SQL]


Question: What is zip code of customer with first name as Carole and last name as Bernhard?

Context: CREATE TABLE Addresses (zip_postcode VARCHAR, address_id VARCHAR); CREATE TABLE Customers (customer_address_id VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT T2.zip_postcode FROM Customers AS T1 JOIN Addresses AS T2 ON T1.customer_address_id = T2.address_id WHERE T1.first_name = "Carole" AND T1.last_name = "Bernhard" [/SQL]


Question: Which city does has most number of customers?

Context: CREATE TABLE Customers (customer_address_id VARCHAR); CREATE TABLE Addresses (city VARCHAR, address_id VARCHAR)

Answer: [SQL] SELECT T2.city FROM Customers AS T1 JOIN Addresses AS T2 ON T1.customer_address_id = T2.address_id GROUP BY T2.city ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: How much in total does customer with first name as Carole and last name as Bernhard paid?

Context: CREATE TABLE Customers (customer_id VARCHAR, first_name VARCHAR, last_name VARCHAR); CREATE TABLE Customer_Payments (amount_payment INTEGER, customer_id VARCHAR)

Answer: [SQL] SELECT SUM(T1.amount_payment) FROM Customer_Payments AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.first_name = "Carole" AND T2.last_name = "Bernhard" [/SQL]


Question: List the number of customers that did not have any payment history.

Context: CREATE TABLE Customers (customer_id VARCHAR); CREATE TABLE Customer_Payments (customer_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Customers WHERE NOT customer_id IN (SELECT customer_id FROM Customer_Payments) [/SQL]


Question: List first name and last name of customers that have more than 2 payments.

Context: CREATE TABLE Customers (first_name VARCHAR, last_name VARCHAR, customer_id VARCHAR); CREATE TABLE Customer_Payments (customer_id VARCHAR)

Answer: [SQL] SELECT T2.first_name, T2.last_name FROM Customer_Payments AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id HAVING COUNT(*) > 2 [/SQL]


Question: List all payment methods and number of payments using each payment methods.

Context: CREATE TABLE Customer_Payments (payment_method_code VARCHAR)

Answer: [SQL] SELECT payment_method_code, COUNT(*) FROM Customer_Payments GROUP BY payment_method_code [/SQL]


Question: How many lessons were in cancelled state?

Context: CREATE TABLE Lessons (lesson_status_code VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Lessons WHERE lesson_status_code = "Cancelled" [/SQL]


Question: List lesson id of all lessons taught by staff with first name as Janessa, last name as Sawayn and nickname containing letter 's'.

Context: CREATE TABLE Lessons (lesson_id VARCHAR, staff_id VARCHAR); CREATE TABLE Staff (staff_id VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT T1.lesson_id FROM Lessons AS T1 JOIN Staff AS T2 ON T1.staff_id = T2.staff_id WHERE T2.first_name = "Janessa" AND T2.last_name = "Sawayn" AND nickname LIKE "%s%" [/SQL]


Question: How many lessons taught by staff whose first name has letter 'a' in it?

Context: CREATE TABLE Lessons (staff_id VARCHAR); CREATE TABLE Staff (staff_id VARCHAR, first_name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Lessons AS T1 JOIN Staff AS T2 ON T1.staff_id = T2.staff_id WHERE T2.first_name LIKE "%a%" [/SQL]


Question: How long is the total lesson time taught by staff with first name as Janessa and last name as Sawayn?

Context: CREATE TABLE Lessons (staff_id VARCHAR); CREATE TABLE Staff (staff_id VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT SUM(lesson_time) FROM Lessons AS T1 JOIN Staff AS T2 ON T1.staff_id = T2.staff_id WHERE T2.first_name = "Janessa" AND T2.last_name = "Sawayn" [/SQL]


Question: What is average lesson price taught by staff with first name as Janessa and last name as Sawayn?

Answer: [SQL] SELECT AVG(price) FROM Lessons AS T1 JOIN Staff AS T2 ON T1.staff_id = T2.staff_id WHERE T2.first_name = "Janessa" AND T2.last_name = "Sawayn" [/SQL]


Question: How many lesson does customer with first name Ray took?

Context: CREATE TABLE Customers (customer_id VARCHAR, first_name VARCHAR); CREATE TABLE Lessons (customer_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Lessons AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.first_name = "Ray" [/SQL]


Question: Which last names are both used by customers and by staff?

Context: CREATE TABLE Customers (last_name VARCHAR); CREATE TABLE Staff (last_name VARCHAR)

Answer: [SQL] SELECT last_name FROM Customers INTERSECT SELECT last_name FROM Staff [/SQL]


Question: What is the first name of the staff who did not give any lesson?

Context: CREATE TABLE Lessons (staff_id VARCHAR); CREATE TABLE Staff (first_name VARCHAR); CREATE TABLE Staff (first_name VARCHAR, staff_id VARCHAR)

Answer: [SQL] SELECT first_name FROM Staff EXCEPT SELECT T2.first_name FROM Lessons AS T1 JOIN Staff AS T2 ON T1.staff_id = T2.staff_id [/SQL]


Question: What is the id and detail of the vehicle used in lessons for most of the times?

Context: CREATE TABLE Lessons (vehicle_id VARCHAR); CREATE TABLE Vehicles (vehicle_id VARCHAR, vehicle_details VARCHAR)

Answer: [SQL] SELECT T1.vehicle_id, T1.vehicle_details FROM Vehicles AS T1 JOIN Lessons AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T1.vehicle_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: How many faculty do we have?

Context: CREATE TABLE Faculty (Id VARCHAR)

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


Question: What ranks do we have for faculty?

Context: CREATE TABLE Faculty (rank VARCHAR)

Answer: [SQL] SELECT DISTINCT rank FROM Faculty [/SQL]


Question: Show all the distinct buildings that have faculty rooms.

Context: CREATE TABLE Faculty (building VARCHAR)

Answer: [SQL] SELECT DISTINCT building FROM Faculty [/SQL]


Question: Show the rank, first name, and last name for all the faculty.

Context: CREATE TABLE Faculty (rank VARCHAR, Fname VARCHAR, Lname VARCHAR)

Answer: [SQL] SELECT rank, Fname, Lname FROM Faculty [/SQL]


Question: Show the first name, last name, and phone number for all female faculty members.

Context: CREATE TABLE Faculty (Fname VARCHAR, Lname VARCHAR, phone VARCHAR, Sex VARCHAR)

Answer: [SQL] SELECT Fname, Lname, phone FROM Faculty WHERE Sex = 'F' [/SQL]


Question: Show ids for all the male faculty.

Context: CREATE TABLE Faculty (FacID VARCHAR, Sex VARCHAR)

Answer: [SQL] SELECT FacID FROM Faculty WHERE Sex = 'M' [/SQL]


Question: How many female Professors do we have?

Context: CREATE TABLE Faculty (Sex VARCHAR, Rank VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Faculty WHERE Sex = 'F' AND Rank = "Professor" [/SQL]


Question: Show the phone, room, and building for the faculty named Jerry Prince.

Context: CREATE TABLE Faculty (phone VARCHAR, room VARCHAR, building VARCHAR, Fname VARCHAR, Lname VARCHAR)

Answer: [SQL] SELECT phone, room, building FROM Faculty WHERE Fname = "Jerry" AND Lname = "Prince" [/SQL]


Question: How many Professors are in building NEB?

Context: CREATE TABLE Faculty (Rank VARCHAR, building VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Faculty WHERE Rank = "Professor" AND building = "NEB" [/SQL]


Question: Show the first name and last name for all the instructors.

Context: CREATE TABLE Faculty (fname VARCHAR, lname VARCHAR, Rank VARCHAR)

Answer: [SQL] SELECT fname, lname FROM Faculty WHERE Rank = "Instructor" [/SQL]


Question: Show all the buildings along with the number of faculty members the buildings have.

Context: CREATE TABLE Faculty (building VARCHAR)

Answer: [SQL] SELECT building, COUNT(*) FROM Faculty GROUP BY building [/SQL]


Question: Which building has most faculty members?

Context: CREATE TABLE Faculty (building VARCHAR)

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


Question: Show all the buildings that have at least 10 professors.

Context: CREATE TABLE Faculty (building VARCHAR, rank VARCHAR)

Answer: [SQL] SELECT building FROM Faculty WHERE rank = "Professor" GROUP BY building HAVING COUNT(*) >= 10 [/SQL]


Question: For each faculty rank, show the number of faculty members who have it.

Context: CREATE TABLE Faculty (rank VARCHAR)

Answer: [SQL] SELECT rank, COUNT(*) FROM Faculty GROUP BY rank [/SQL]


Question: Show all the ranks and the number of male and female faculty for each rank.

Context: CREATE TABLE Faculty (rank VARCHAR, sex VARCHAR)

Answer: [SQL] SELECT rank, sex, COUNT(*) FROM Faculty GROUP BY rank, sex [/SQL]


Question: Which rank has the smallest number of faculty members?

Context: CREATE TABLE Faculty (rank VARCHAR)

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


Question: Show the number of male and female assistant professors.

Context: CREATE TABLE Faculty (sex VARCHAR, rank VARCHAR)

Answer: [SQL] SELECT sex, COUNT(*) FROM Faculty WHERE rank = "AsstProf" GROUP BY sex [/SQL]


Question: What are the first name and last name of Linda Smith's advisor?

Context: CREATE TABLE Student (advisor VARCHAR, fname VARCHAR, lname VARCHAR); CREATE TABLE Faculty (fname VARCHAR, lname VARCHAR, FacID VARCHAR)

Answer: [SQL] SELECT T1.fname, T1.lname FROM Faculty AS T1 JOIN Student AS T2 ON T1.FacID = T2.advisor WHERE T2.fname = "Linda" AND T2.lname = "Smith" [/SQL]


Question: Show the ids of students whose advisors are professors.

Context: CREATE TABLE Student (StuID VARCHAR, advisor VARCHAR); CREATE TABLE Faculty (FacID VARCHAR, rank VARCHAR)

Answer: [SQL] SELECT T2.StuID FROM Faculty AS T1 JOIN Student AS T2 ON T1.FacID = T2.advisor WHERE T1.rank = "Professor" [/SQL]


Question: Show first name and last name for all the students advised by Michael Goodrich.

Context: CREATE TABLE Faculty (FacID VARCHAR, fname VARCHAR, lname VARCHAR); CREATE TABLE Student (fname VARCHAR, lname VARCHAR, advisor VARCHAR)

Answer: [SQL] SELECT T2.fname, T2.lname FROM Faculty AS T1 JOIN Student AS T2 ON T1.FacID = T2.advisor WHERE T1.fname = "Michael" AND T1.lname = "Goodrich" [/SQL]


Question: Show the faculty id of each faculty member, along with the number of students he or she advises.

Context: CREATE TABLE Faculty (FacID VARCHAR); CREATE TABLE Student (advisor VARCHAR)

Answer: [SQL] SELECT T1.FacID, COUNT(*) FROM Faculty AS T1 JOIN Student AS T2 ON T1.FacID = T2.advisor GROUP BY T1.FacID [/SQL]


Question: Show all the faculty ranks and the number of students advised by each rank.

Context: CREATE TABLE Student (advisor VARCHAR); CREATE TABLE Faculty (rank VARCHAR, FacID VARCHAR)

Answer: [SQL] SELECT T1.rank, COUNT(*) FROM Faculty AS T1 JOIN Student AS T2 ON T1.FacID = T2.advisor GROUP BY T1.rank [/SQL]


Question: What are the first and last name of the faculty who has the most students?

Context: CREATE TABLE Student (advisor VARCHAR); CREATE TABLE Faculty (fname VARCHAR, lname VARCHAR, FacID VARCHAR)

Answer: [SQL] SELECT T1.fname, T1.lname FROM Faculty AS T1 JOIN Student AS T2 ON T1.FacID = T2.advisor GROUP BY T1.FacID ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the ids for all the faculty members who have at least 2 students.

Answer: [SQL] SELECT T1.FacID FROM Faculty AS T1 JOIN Student AS T2 ON T1.FacID = T2.advisor GROUP BY T1.FacID HAVING COUNT(*) >= 2 [/SQL]


Question: Show ids for the faculty members who don't advise any student.

Context: CREATE TABLE Faculty (FacID VARCHAR, advisor VARCHAR); CREATE TABLE Student (FacID VARCHAR, advisor VARCHAR)

Answer: [SQL] SELECT FacID FROM Faculty EXCEPT SELECT advisor FROM Student [/SQL]


Question: What activities do we have?

Context: CREATE TABLE Activity (activity_name VARCHAR)

Answer: [SQL] SELECT activity_name FROM Activity [/SQL]


Question: How many activities do we have?

Context: CREATE TABLE Activity (Id VARCHAR)

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


Question: How many faculty members participate in an activity?

Context: CREATE TABLE Faculty_participates_in (FacID VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT FacID) FROM Faculty_participates_in [/SQL]


Question: Show the ids of the faculty who don't participate in any activity.

Context: CREATE TABLE Faculty (FacID VARCHAR); CREATE TABLE Faculty_participates_in (FacID VARCHAR)

Answer: [SQL] SELECT FacID FROM Faculty EXCEPT SELECT FacID FROM Faculty_participates_in [/SQL]


Question: Show the ids of all the faculty members who participate in an activity and advise a student.

Context: CREATE TABLE Student (FacID VARCHAR, advisor VARCHAR); CREATE TABLE Faculty_participates_in (FacID VARCHAR, advisor VARCHAR)

Answer: [SQL] SELECT FacID FROM Faculty_participates_in INTERSECT SELECT advisor FROM Student [/SQL]


Question: How many activities does Mark Giuliano participate in?

Context: CREATE TABLE Faculty_participates_in (facID VARCHAR); CREATE TABLE Faculty (facID VARCHAR, fname VARCHAR, lname VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Faculty AS T1 JOIN Faculty_participates_in AS T2 ON T1.facID = T2.facID WHERE T1.fname = "Mark" AND T1.lname = "Giuliano" [/SQL]


Question: Show the names of all the activities Mark Giuliano participates in.

Context: CREATE TABLE Activity (activity_name VARCHAR, actid VARCHAR); CREATE TABLE Faculty (facID VARCHAR, fname VARCHAR, lname VARCHAR); CREATE TABLE Faculty_participates_in (facID VARCHAR, actid VARCHAR)

Answer: [SQL] SELECT T3.activity_name FROM Faculty AS T1 JOIN Faculty_participates_in AS T2 ON T1.facID = T2.facID JOIN Activity AS T3 ON T3.actid = T2.actid WHERE T1.fname = "Mark" AND T1.lname = "Giuliano" [/SQL]


Question: Show the first and last name of all the faculty members who participated in some activity, together with the number of activities they participated in.

Context: CREATE TABLE Faculty_participates_in (facID VARCHAR); CREATE TABLE Faculty (fname VARCHAR, lname VARCHAR, FacID VARCHAR, facID VARCHAR)

Answer: [SQL] SELECT T1.fname, T1.lname, COUNT(*), T1.FacID FROM Faculty AS T1 JOIN Faculty_participates_in AS T2 ON T1.facID = T2.facID GROUP BY T1.FacID [/SQL]


Question: Show all the activity names and the number of faculty involved in each activity.

Context: CREATE TABLE Faculty_participates_in (actID VARCHAR); CREATE TABLE Activity (activity_name VARCHAR, actID VARCHAR)

Answer: [SQL] SELECT T1.activity_name, COUNT(*) FROM Activity AS T1 JOIN Faculty_participates_in AS T2 ON T1.actID = T2.actID GROUP BY T1.actID [/SQL]


Question: What is the first and last name of the faculty participating in the most activities?

Answer: [SQL] SELECT T1.fname, T1.lname FROM Faculty AS T1 JOIN Faculty_participates_in AS T2 ON T1.facID = T2.facID GROUP BY T1.FacID ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the name of the activity that has the most faculty members involved in?

Answer: [SQL] SELECT T1.activity_name FROM Activity AS T1 JOIN Faculty_participates_in AS T2 ON T1.actID = T2.actID GROUP BY T1.actID ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the ids of the students who don't participate in any activity.

Context: CREATE TABLE Participates_in (StuID VARCHAR); CREATE TABLE Student (StuID VARCHAR)

Answer: [SQL] SELECT StuID FROM Student EXCEPT SELECT StuID FROM Participates_in [/SQL]


Question: Show the ids for all the students who participate in an activity and are under 20.

Context: CREATE TABLE Student (StuID VARCHAR, age INTEGER); CREATE TABLE Participates_in (StuID VARCHAR, age INTEGER)

Answer: [SQL] SELECT StuID FROM Participates_in INTERSECT SELECT StuID FROM Student WHERE age < 20 [/SQL]


Question: What is the first and last name of the student participating in the most activities?

Context: CREATE TABLE Student (fname VARCHAR, lname VARCHAR, StuID VARCHAR); CREATE TABLE Participates_in (StuID VARCHAR)

Answer: [SQL] SELECT T1.fname, T1.lname FROM Student AS T1 JOIN Participates_in AS T2 ON T1.StuID = T2.StuID GROUP BY T1.StuID ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the name of the activity with the most students?

Context: CREATE TABLE Participates_in (actID VARCHAR); CREATE TABLE Activity (activity_name VARCHAR, actID VARCHAR)

Answer: [SQL] SELECT T1.activity_name FROM Activity AS T1 JOIN Participates_in AS T2 ON T1.actID = T2.actID GROUP BY T1.actID ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the first names of the faculty members who are playing Canoeing or Kayaking.

Context: CREATE TABLE activity (activity_name VARCHAR); CREATE TABLE Faculty_participates_in (facID VARCHAR, actid VARCHAR); CREATE TABLE Faculty (lname VARCHAR, facID VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.lname FROM Faculty AS T1 JOIN Faculty_participates_in AS T2 ON T1.facID = T2.facID JOIN activity AS T3 ON T2.actid = T2.actid WHERE T3.activity_name = 'Canoeing' OR T3.activity_name = 'Kayaking' [/SQL]


Question: Find the first names of professors who are not playing Canoeing or Kayaking.

Context: CREATE TABLE faculty (lname VARCHAR, rank VARCHAR); CREATE TABLE activity (activity_name VARCHAR); CREATE TABLE Faculty_participates_in (facID VARCHAR, actid VARCHAR); CREATE TABLE Faculty (lname VARCHAR, facID VARCHAR)

Answer: [SQL] SELECT lname FROM faculty WHERE rank = 'Professor' EXCEPT SELECT DISTINCT T1.lname FROM Faculty AS T1 JOIN Faculty_participates_in AS T2 ON T1.facID = T2.facID JOIN activity AS T3 ON T2.actid = T2.actid WHERE T3.activity_name = 'Canoeing' OR T3.activity_name = 'Kayaking' [/SQL]


Question: Find the first names of the faculty members who participate in Canoeing and Kayaking.

Answer: [SQL] SELECT T1.lname FROM Faculty AS T1 JOIN Faculty_participates_in AS T2 ON T1.facID = T2.facID JOIN activity AS T3 ON T2.actid = T2.actid WHERE T3.activity_name = 'Canoeing' INTERSECT SELECT T1.lname FROM Faculty AS T1 JOIN Faculty_participates_in AS T2 ON T1.facID = T2.facID JOIN activity AS T3 ON T2.actid = T2.actid WHERE T3.activity_name = 'Kayaking' [/SQL]


Question: Find the ids of the students who participate in Canoeing and Kayaking.

Context: CREATE TABLE activity (actid VARCHAR, activity_name VARCHAR); CREATE TABLE participates_in (stuid VARCHAR)

Answer: [SQL] SELECT T1.stuid FROM participates_in AS T1 JOIN activity AS T2 ON T2.actid = T2.actid WHERE T2.activity_name = 'Canoeing' INTERSECT SELECT T1.stuid FROM participates_in AS T1 JOIN activity AS T2 ON T2.actid = T2.actid WHERE T2.activity_name = 'Kayaking' [/SQL]


Question: Find the name of the airport in the city of Goroka.

Context: CREATE TABLE airports (name VARCHAR, city VARCHAR)

Answer: [SQL] SELECT name FROM airports WHERE city = 'Goroka' [/SQL]


Question: Find the name, city, country, and altitude (or elevation) of the airports in the city of New York.

Context: CREATE TABLE airports (name VARCHAR, city VARCHAR, country VARCHAR, elevation VARCHAR)

Answer: [SQL] SELECT name, city, country, elevation FROM airports WHERE city = 'New York' [/SQL]


Question: How many airlines are there?

Context: CREATE TABLE airlines (Id VARCHAR)

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


Question: How many airlines does Russia has?

Context: CREATE TABLE airlines (country VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM airlines WHERE country = 'Russia' [/SQL]


Question: What is the maximum elevation of all airports in the country of Iceland?

Context: CREATE TABLE airports (elevation INTEGER, country VARCHAR)

Answer: [SQL] SELECT MAX(elevation) FROM airports WHERE country = 'Iceland' [/SQL]


Question: Find the name of the airports located in Cuba or Argentina.

Context: CREATE TABLE airports (name VARCHAR, country VARCHAR)

Answer: [SQL] SELECT name FROM airports WHERE country = 'Cuba' OR country = 'Argentina' [/SQL]


Question: Find the country of the airlines whose name starts with 'Orbit'.

Context: CREATE TABLE airlines (country VARCHAR, name VARCHAR)

Answer: [SQL] SELECT country FROM airlines WHERE name LIKE 'Orbit%' [/SQL]


Question: Find the name of airports whose altitude is between -50 and 50.

Context: CREATE TABLE airports (name VARCHAR, elevation INTEGER)

Answer: [SQL] SELECT name FROM airports WHERE elevation BETWEEN -50 AND 50 [/SQL]


Question: Which country is the airport that has the highest altitude located in?

Context: CREATE TABLE airports (country VARCHAR, elevation VARCHAR)

Answer: [SQL] SELECT country FROM airports ORDER BY elevation DESC LIMIT 1 [/SQL]


Question: Find the number of airports whose name contain the word 'International'.

Context: CREATE TABLE airports (name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM airports WHERE name LIKE '%International%' [/SQL]


Question: How many different cities do have some airport in the country of Greenland?

Context: CREATE TABLE airports (city VARCHAR, country VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT city) FROM airports WHERE country = 'Greenland' [/SQL]


Question: Find the number of routes operated by American Airlines.

Context: CREATE TABLE routes (alid VARCHAR); CREATE TABLE airlines (alid VARCHAR, name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid WHERE T1.name = 'American Airlines' [/SQL]


Question: Find the number of routes whose destination airports are in Canada.

Context: CREATE TABLE routes (dst_apid VARCHAR); CREATE TABLE airports (apid VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid WHERE country = 'Canada' [/SQL]


Question: Find the name, city, and country of the airport that has the lowest altitude.

Answer: [SQL] SELECT name, city, country FROM airports ORDER BY elevation LIMIT 1 [/SQL]


Question: Find the name, city, and country of the airport that has the highest latitude.

Answer: [SQL] SELECT name, city, country FROM airports ORDER BY elevation DESC LIMIT 1 [/SQL]


Question: Find the name and city of the airport which is the destination of the most number of routes.

Context: CREATE TABLE airports (name VARCHAR, city VARCHAR, apid VARCHAR); CREATE TABLE routes (dst_apid VARCHAR)

Answer: [SQL] SELECT T1.name, T1.city, T2.dst_apid FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid GROUP BY T2.dst_apid ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the names of the top 10 airlines that operate the most number of routes.

Context: CREATE TABLE airlines (name VARCHAR, alid VARCHAR); CREATE TABLE routes (alid VARCHAR)

Answer: [SQL] SELECT T1.name, T2.alid FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid GROUP BY T2.alid ORDER BY COUNT(*) DESC LIMIT 10 [/SQL]


Question: Find the name and city of the airport which is the source for the most number of flight routes.

Context: CREATE TABLE airports (name VARCHAR, city VARCHAR, apid VARCHAR); CREATE TABLE routes (src_apid VARCHAR)

Answer: [SQL] SELECT T1.name, T1.city, T2.src_apid FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid GROUP BY T2.src_apid ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the number of different airports which are the destinations of the American Airlines.

Answer: [SQL] SELECT COUNT(DISTINCT dst_apid) FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid WHERE T1.name = 'American Airlines' [/SQL]


Question: Which countries has the most number of airlines?

Context: CREATE TABLE airlines (country VARCHAR)

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


Question: Which countries has the most number of airlines whose active status is 'Y'?

Context: CREATE TABLE airlines (country VARCHAR, active VARCHAR)

Answer: [SQL] SELECT country FROM airlines WHERE active = 'Y' GROUP BY country ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: List all countries and their number of airlines in the descending order of number of airlines.

Context: CREATE TABLE airlines (country VARCHAR)

Answer: [SQL] SELECT country, COUNT(*) FROM airlines GROUP BY country ORDER BY COUNT(*) DESC [/SQL]


Question: How many airports are there per country? Order the countries by decreasing number of airports.

Context: CREATE TABLE airports (country VARCHAR)

Answer: [SQL] SELECT COUNT(*), country FROM airports GROUP BY country ORDER BY COUNT(*) DESC [/SQL]


Question: How many airports are there per city in the United States? Order the cities by decreasing number of airports.

Answer: [SQL] SELECT COUNT(*), city FROM airports WHERE country = 'United States' GROUP BY city ORDER BY COUNT(*) DESC [/SQL]


Question: Return the cities with more than 3 airports in the United States.

Answer: [SQL] SELECT city FROM airports WHERE country = 'United States' GROUP BY city HAVING COUNT(*) > 3 [/SQL]


Question: How many cities are there that have more than 3 airports?

Context: CREATE TABLE airports (city VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM (SELECT city FROM airports GROUP BY city HAVING COUNT(*) > 3) [/SQL]


Question: List the cities which have more than one airport and number of airports.

Context: CREATE TABLE airports (city VARCHAR)

Answer: [SQL] SELECT city, COUNT(*) FROM airports GROUP BY city HAVING COUNT(*) > 1 [/SQL]


Question: List the cities which have more than 2 airports sorted by the number of airports.

Context: CREATE TABLE airports (city VARCHAR)

Answer: [SQL] SELECT city FROM airports GROUP BY city HAVING COUNT(*) > 2 ORDER BY COUNT(*) [/SQL]


Question: Find the number of routes for each source airport and the airport name.

Context: CREATE TABLE airports (name VARCHAR, apid VARCHAR); CREATE TABLE routes (src_apid VARCHAR)

Answer: [SQL] SELECT COUNT(*), T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid GROUP BY T1.name [/SQL]


Question: Find the number of routes and airport name for each source airport, order the results by decreasing number of routes.

Answer: [SQL] SELECT COUNT(*), T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid GROUP BY T1.name ORDER BY COUNT(*) DESC [/SQL]


Question: Find the average elevation of all airports for each country.

Context: CREATE TABLE airports (country VARCHAR, elevation INTEGER)

Answer: [SQL] SELECT AVG(elevation), country FROM airports GROUP BY country [/SQL]


Question: Find the cities which have exactly two airports.

Context: CREATE TABLE airports (city VARCHAR)

Answer: [SQL] SELECT city FROM airports GROUP BY city HAVING COUNT(*) = 2 [/SQL]


Question: For each country and airline name, how many routes are there?

Context: CREATE TABLE airlines (country VARCHAR, name VARCHAR, alid VARCHAR); CREATE TABLE routes (alid VARCHAR)

Answer: [SQL] SELECT T1.country, T1.name, COUNT(*) FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid GROUP BY T1.country, T1.name [/SQL]


Question: Find the number of routes with destination airports in Italy.

Context: CREATE TABLE routes (dst_apid VARCHAR); CREATE TABLE airports (apid VARCHAR, country VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM routes AS T1 JOIN airports AS T2 ON T1.dst_apid = T2.apid WHERE T2.country = 'Italy' [/SQL]


Question: Return the number of routes with destination airport in Italy operated by the airline with name 'American Airlines'.

Context: CREATE TABLE routes (dst_apid VARCHAR, alid VARCHAR); CREATE TABLE airports (apid VARCHAR, country VARCHAR); CREATE TABLE airlines (alid VARCHAR, name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM routes AS T1 JOIN airports AS T2 ON T1.dst_apid = T2.apid JOIN airlines AS T3 ON T1.alid = T3.alid WHERE T2.country = 'Italy' AND T3.name = 'American Airlines' [/SQL]


Question: Find the number of routes that have destination John F Kennedy International Airport.

Context: CREATE TABLE airports (apid VARCHAR, name VARCHAR); CREATE TABLE routes (dst_apid VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid WHERE T1.name = 'John F Kennedy International Airport' [/SQL]


Question: Find the number of routes from the United States to Canada.

Context: CREATE TABLE airports (dst_apid VARCHAR, src_apid VARCHAR, apid VARCHAR, country VARCHAR); CREATE TABLE routes (dst_apid VARCHAR, src_apid VARCHAR, apid VARCHAR, country VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM routes WHERE dst_apid IN (SELECT apid FROM airports WHERE country = 'Canada') AND src_apid IN (SELECT apid FROM airports WHERE country = 'United States') [/SQL]


Question: Find the id of routes whose source and destination airports are in the United States.

Context: CREATE TABLE routes (rid VARCHAR, dst_apid VARCHAR, src_apid VARCHAR, apid VARCHAR, country VARCHAR); CREATE TABLE airports (rid VARCHAR, dst_apid VARCHAR, src_apid VARCHAR, apid VARCHAR, country VARCHAR)

Answer: [SQL] SELECT rid FROM routes WHERE dst_apid IN (SELECT apid FROM airports WHERE country = 'United States') AND src_apid IN (SELECT apid FROM airports WHERE country = 'United States') [/SQL]


Question: Find the name of airline which runs the most number of routes.

Answer: [SQL] SELECT T1.name FROM airlines AS T1 JOIN routes AS T2 ON T1.alid = T2.alid GROUP BY T1.name ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the busiest source airport that runs most number of routes in China.

Context: CREATE TABLE routes (src_apid VARCHAR); CREATE TABLE airports (name VARCHAR, apid VARCHAR, country VARCHAR)

Answer: [SQL] SELECT T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.src_apid WHERE T1.country = 'China' GROUP BY T1.name ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the busiest destination airport that runs most number of routes in China.

Context: CREATE TABLE routes (dst_apid VARCHAR); CREATE TABLE airports (name VARCHAR, apid VARCHAR, country VARCHAR)

Answer: [SQL] SELECT T1.name FROM airports AS T1 JOIN routes AS T2 ON T1.apid = T2.dst_apid WHERE T1.country = 'China' GROUP BY T1.name ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the id of the most recent order?

Context: CREATE TABLE orders (order_id VARCHAR, date_order_placed VARCHAR)

Answer: [SQL] SELECT order_id FROM orders ORDER BY date_order_placed DESC LIMIT 1 [/SQL]


Question: what are the order id and customer id of the oldest order?

Context: CREATE TABLE orders (order_id VARCHAR, customer_id VARCHAR, date_order_placed VARCHAR)

Answer: [SQL] SELECT order_id, customer_id FROM orders ORDER BY date_order_placed LIMIT 1 [/SQL]


Question: Find the id of the order whose shipment tracking number is "3452".

Context: CREATE TABLE shipments (order_id VARCHAR, shipment_tracking_number VARCHAR)

Answer: [SQL] SELECT order_id FROM shipments WHERE shipment_tracking_number = "3452" [/SQL]


Question: Find the ids of all the order items whose product id is 11.

Context: CREATE TABLE order_items (order_item_id VARCHAR, product_id VARCHAR)

Answer: [SQL] SELECT order_item_id FROM order_items WHERE product_id = 11 [/SQL]


Question: List the name of all the distinct customers who have orders with status "Packing".

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

Answer: [SQL] SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Packing" [/SQL]


Question: Find the details of all the distinct customers who have orders with status "On Road".

Context: CREATE TABLE orders (customer_id VARCHAR, order_status VARCHAR); CREATE TABLE customers (customer_details VARCHAR, customer_id VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.customer_details FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road" [/SQL]


Question: What is the name of the customer who has the most orders?

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

Answer: [SQL] SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the customer id of the customer who has the most orders?

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

Answer: [SQL] SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Give me a list of id and status of orders which belong to the customer named "Jeramie".

Context: CREATE TABLE customers (customer_id VARCHAR, customer_name VARCHAR); CREATE TABLE orders (order_id VARCHAR, order_status VARCHAR, customer_id VARCHAR)

Answer: [SQL] SELECT T2.order_id, T2.order_status FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T1.customer_name = "Jeramie" [/SQL]


Question: Find the dates of orders which belong to the customer named "Jeramie".

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

Answer: [SQL] SELECT T2.date_order_placed FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T1.customer_name = "Jeramie" [/SQL]


Question: Give me the names of customers who have placed orders between 2009-01-01 and 2010-01-01.

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

Answer: [SQL] SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.date_order_placed >= "2009-01-01" AND T2.date_order_placed <= "2010-01-01" [/SQL]


Question: Give me a list of distinct product ids from orders placed between 1975-01-01 and 1976-01-01?

Context: CREATE TABLE order_items (product_id VARCHAR, order_id VARCHAR); CREATE TABLE orders (order_id VARCHAR, date_order_placed VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.product_id FROM orders AS T1 JOIN order_items AS T2 ON T1.order_id = T2.order_id WHERE T1.date_order_placed >= "1975-01-01" AND T1.date_order_placed <= "1976-01-01" [/SQL]


Question: Find the names of the customers who have order status both "On Road" and "Shipped".

Answer: [SQL] SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road" INTERSECT SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Shipped" [/SQL]


Question: Find the id of the customers who have order status both "On Road" and "Shipped".

Context: CREATE TABLE customers (customer_id VARCHAR); CREATE TABLE orders (customer_id VARCHAR, order_status VARCHAR)

Answer: [SQL] SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road" INTERSECT SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Shipped" [/SQL]


Question: When was the order placed whose shipment tracking number is 3452? Give me the date.

Context: CREATE TABLE shipments (order_id VARCHAR, shipment_tracking_number VARCHAR); CREATE TABLE orders (date_order_placed VARCHAR, order_id VARCHAR)

Answer: [SQL] SELECT T1.date_order_placed FROM orders AS T1 JOIN shipments AS T2 ON T1.order_id = T2.order_id WHERE T2.shipment_tracking_number = 3452 [/SQL]


Question: What is the placement date of the order whose invoice number is 10?

Context: CREATE TABLE orders (date_order_placed VARCHAR, order_id VARCHAR); CREATE TABLE shipments (order_id VARCHAR, invoice_number VARCHAR)

Answer: [SQL] SELECT T1.date_order_placed FROM orders AS T1 JOIN shipments AS T2 ON T1.order_id = T2.order_id WHERE T2.invoice_number = 10 [/SQL]


Question: List the count and id of each product in all the orders.

Context: CREATE TABLE orders (order_id VARCHAR); CREATE TABLE order_items (order_id VARCHAR, product_id VARCHAR); CREATE TABLE products (product_id VARCHAR)

Answer: [SQL] SELECT COUNT(*), T3.product_id FROM orders AS T1 JOIN order_items AS T2 JOIN products AS T3 ON T1.order_id = T2.order_id AND T2.product_id = T3.product_id GROUP BY T3.product_id [/SQL]


Question: List the name and count of each product in all orders.

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

Answer: [SQL] SELECT T3.product_name, COUNT(*) FROM orders AS T1 JOIN order_items AS T2 JOIN products AS T3 ON T1.order_id = T2.order_id AND T2.product_id = T3.product_id GROUP BY T3.product_id [/SQL]


Question: Find the ids of orders which are shipped after 2000-01-01.

Context: CREATE TABLE shipments (order_id VARCHAR, shipment_date INTEGER)

Answer: [SQL] SELECT order_id FROM shipments WHERE shipment_date > "2000-01-01" [/SQL]


Question: Find the id of the order which is shipped most recently.

Answer: [SQL] SELECT order_id FROM shipments WHERE shipment_date = (SELECT MAX(shipment_date) FROM shipments) [/SQL]


Question: List the names of all distinct products in alphabetical order.

Context: CREATE TABLE products (product_name VARCHAR)

Answer: [SQL] SELECT DISTINCT product_name FROM products ORDER BY product_name [/SQL]