Question: What are the email addresses of the drama workshop groups with address in Alaska state?

Context: CREATE TABLE Drama_Workshop_Groups (Store_Email_Address VARCHAR, Address_ID VARCHAR); CREATE TABLE Addresses (Address_ID VARCHAR, State_County VARCHAR)

Answer: [SQL] SELECT T2.Store_Email_Address FROM Addresses AS T1 JOIN Drama_Workshop_Groups AS T2 ON T1.Address_ID = T2.Address_ID WHERE T1.State_County = "Alaska" [/SQL]


Question: Show all cities along with the number of drama workshop groups in each city.

Context: CREATE TABLE Addresses (City_Town VARCHAR, Address_ID VARCHAR); CREATE TABLE Drama_Workshop_Groups (Address_ID VARCHAR)

Answer: [SQL] SELECT T1.City_Town, COUNT(*) FROM Addresses AS T1 JOIN Drama_Workshop_Groups AS T2 ON T1.Address_ID = T2.Address_ID GROUP BY T1.City_Town [/SQL]


Question: What is the marketing region code that has the most drama workshop groups?

Context: CREATE TABLE Drama_Workshop_Groups (Marketing_Region_Code VARCHAR)

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


Question: Show all cities where at least one customer lives in but no performer lives in.

Context: CREATE TABLE Customers (Address_ID VARCHAR); CREATE TABLE Addresses (City_Town VARCHAR, Address_ID VARCHAR); CREATE TABLE Performers (Address_ID VARCHAR)

Answer: [SQL] SELECT T1.City_Town FROM Addresses AS T1 JOIN Customers AS T2 ON T1.Address_ID = T2.Address_ID EXCEPT SELECT T1.City_Town FROM Addresses AS T1 JOIN Performers AS T2 ON T1.Address_ID = T2.Address_ID [/SQL]


Question: What is the most frequent status of bookings?

Context: CREATE TABLE BOOKINGS (Status_Code VARCHAR)

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


Question: What are the names of the workshop groups that have bookings with status code "stop"?

Context: CREATE TABLE Bookings (Workshop_Group_ID VARCHAR, Status_Code VARCHAR); CREATE TABLE Drama_Workshop_Groups (Store_Name VARCHAR, Workshop_Group_ID VARCHAR)

Answer: [SQL] SELECT T2.Store_Name FROM Bookings AS T1 JOIN Drama_Workshop_Groups AS T2 ON T1.Workshop_Group_ID = T2.Workshop_Group_ID WHERE T1.Status_Code = "stop" [/SQL]


Question: Show the names of all the clients with no booking.

Context: CREATE TABLE Clients (Customer_Name VARCHAR, Client_ID VARCHAR); CREATE TABLE Bookings (Customer_ID VARCHAR); CREATE TABLE Clients (Customer_Name VARCHAR)

Answer: [SQL] SELECT Customer_Name FROM Clients EXCEPT SELECT T2.Customer_Name FROM Bookings AS T1 JOIN Clients AS T2 ON T1.Customer_ID = T2.Client_ID [/SQL]


Question: What is the average quantities ordered with payment method code "MasterCard" on invoices?

Context: CREATE TABLE Invoices (Order_Quantity INTEGER, payment_method_code VARCHAR)

Answer: [SQL] SELECT AVG(Order_Quantity) FROM Invoices WHERE payment_method_code = "MasterCard" [/SQL]


Question: What is the product ID of the most frequently ordered item on invoices?

Context: CREATE TABLE INVOICES (Product_ID VARCHAR)

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


Question: What is the description of the service type which offers both the photo product and the film product?

Context: CREATE TABLE Ref_Service_Types (Service_Type_Description VARCHAR, Service_Type_Code VARCHAR); CREATE TABLE Services (Service_Type_Code VARCHAR, Product_Name VARCHAR)

Answer: [SQL] SELECT T1.Service_Type_Description FROM Ref_Service_Types AS T1 JOIN Services AS T2 ON T1.Service_Type_Code = T2.Service_Type_Code WHERE T2.Product_Name = 'photo' INTERSECT SELECT T1.Service_Type_Description FROM Ref_Service_Types AS T1 JOIN Services AS T2 ON T1.Service_Type_Code = T2.Service_Type_Code WHERE T2.Product_Name = 'film' [/SQL]


Question: How many bands are there?

Context: CREATE TABLE Band (Id VARCHAR)

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


Question: What are all the labels?

Context: CREATE TABLE Albums (label VARCHAR)

Answer: [SQL] SELECT DISTINCT label FROM Albums [/SQL]


Question: Find all the albums in 2012.

Context: CREATE TABLE Albums (YEAR VARCHAR)

Answer: [SQL] SELECT * FROM Albums WHERE YEAR = 2012 [/SQL]


Question: Find all the stage positions of the musicians with first name "Solveig"

Context: CREATE TABLE Band (id VARCHAR); CREATE TABLE Performance (stageposition VARCHAR, bandmate VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.stageposition FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id WHERE Firstname = "Solveig" [/SQL]


Question: How many songs are there?

Context: CREATE TABLE Songs (Id VARCHAR)

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


Question: Find all the songs performed by artist with last name "Heilo"

Context: CREATE TABLE Songs (Title VARCHAR, SongId VARCHAR); CREATE TABLE Performance (bandmate VARCHAR, SongId VARCHAR); CREATE TABLE Band (id VARCHAR, Lastname VARCHAR)

Answer: [SQL] SELECT T3.Title FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id JOIN Songs AS T3 ON T3.SongId = T1.SongId WHERE T2.Lastname = "Heilo" [/SQL]


Question: Hom many musicians performed in the song "Flash"?

Context: CREATE TABLE performance (bandmate VARCHAR, songid VARCHAR); CREATE TABLE songs (songid VARCHAR, Title VARCHAR); CREATE TABLE band (id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM performance AS T1 JOIN band AS T2 ON T1.bandmate = T2.id JOIN songs AS T3 ON T3.songid = T1.songid WHERE T3.Title = "Flash" [/SQL]


Question: Find all the songs produced by artists with first name "Marianne".

Context: CREATE TABLE Songs (Title VARCHAR, SongId VARCHAR); CREATE TABLE Performance (bandmate VARCHAR, SongId VARCHAR); CREATE TABLE Band (id VARCHAR, firstname VARCHAR)

Answer: [SQL] SELECT T3.Title FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id JOIN Songs AS T3 ON T3.SongId = T1.SongId WHERE T2.firstname = "Marianne" [/SQL]


Question: Who performed the song named "Badlands"? Show the first name and the last name.

Context: CREATE TABLE Band (firstname VARCHAR, lastname VARCHAR, id VARCHAR); CREATE TABLE Performance (bandmate VARCHAR, SongId VARCHAR); CREATE TABLE Songs (SongId VARCHAR, Title VARCHAR)

Answer: [SQL] SELECT T2.firstname, T2.lastname FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id JOIN Songs AS T3 ON T3.SongId = T1.SongId WHERE T3.Title = "Badlands" [/SQL]


Question: Who is performing in the back stage position for the song "Badlands"? Show the first name and the last name.

Context: CREATE TABLE Band (firstname VARCHAR, lastname VARCHAR, id VARCHAR); CREATE TABLE Performance (bandmate VARCHAR, SongId VARCHAR, StagePosition VARCHAR); CREATE TABLE Songs (SongId VARCHAR, Title VARCHAR)

Answer: [SQL] SELECT T2.firstname, T2.lastname FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id JOIN Songs AS T3 ON T3.SongId = T1.SongId WHERE T3.Title = "Badlands" AND T1.StagePosition = "back" [/SQL]


Question: How many unique labels are there for albums?

Context: CREATE TABLE albums (label VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT label) FROM albums [/SQL]


Question: What is the label that has the most albums?

Context: CREATE TABLE albums (label VARCHAR)

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


Question: What is the last name of the musician that have produced the most number of songs?

Context: CREATE TABLE Songs (SongId VARCHAR); CREATE TABLE Band (lastname VARCHAR, id VARCHAR); CREATE TABLE Performance (bandmate VARCHAR, SongId VARCHAR)

Answer: [SQL] SELECT T2.lastname FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id JOIN Songs AS T3 ON T3.SongId = T1.SongId GROUP BY lastname ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the last name of the musician that has been at the back position the most?

Context: CREATE TABLE Band (lastname VARCHAR, id VARCHAR); CREATE TABLE Performance (bandmate VARCHAR)

Answer: [SQL] SELECT T2.lastname FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id WHERE stageposition = "back" GROUP BY lastname ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find all the songs whose name contains the word "the".

Context: CREATE TABLE songs (title VARCHAR)

Answer: [SQL] SELECT title FROM songs WHERE title LIKE '% the %' [/SQL]


Question: What are all the instruments used?

Context: CREATE TABLE Instruments (instrument VARCHAR)

Answer: [SQL] SELECT DISTINCT instrument FROM Instruments [/SQL]


Question: What instrument did the musician with last name "Heilo" use in the song "Le Pop"?

Context: CREATE TABLE Songs (SongId VARCHAR, songid VARCHAR, title VARCHAR); CREATE TABLE Performance (bandmate VARCHAR, SongId VARCHAR); CREATE TABLE Band (id VARCHAR, lastname VARCHAR); CREATE TABLE Instruments (instrument VARCHAR, songid VARCHAR, bandmateid VARCHAR)

Answer: [SQL] SELECT T4.instrument FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id JOIN Songs AS T3 ON T3.SongId = T1.SongId JOIN Instruments AS T4 ON T4.songid = T3.songid AND T4.bandmateid = T2.id WHERE T2.lastname = "Heilo" AND T3.title = "Le Pop" [/SQL]


Question: What is the most used instrument?

Context: CREATE TABLE instruments (instrument VARCHAR)

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


Question: How many songs have used the instrument "drums"?

Answer: [SQL] SELECT COUNT(*) FROM instruments WHERE instrument = "drums" [/SQL]


Question: What instruments does the the song "Le Pop" use?

Context: CREATE TABLE instruments (songid VARCHAR); CREATE TABLE songs (songid VARCHAR)

Answer: [SQL] SELECT instrument FROM instruments AS T1 JOIN songs AS T2 ON T1.songid = T2.songid WHERE title = "Le Pop" [/SQL]


Question: How many instruments does the song "Le Pop" use?

Answer: [SQL] SELECT COUNT(DISTINCT instrument) FROM instruments AS T1 JOIN songs AS T2 ON T1.songid = T2.songid WHERE title = "Le Pop" [/SQL]


Question: How many instrument does the musician with last name "Heilo" use?

Context: CREATE TABLE instruments (bandmateid VARCHAR); CREATE TABLE Band (id VARCHAR, lastname VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT instrument) FROM instruments AS T1 JOIN Band AS T2 ON T1.bandmateid = T2.id WHERE T2.lastname = "Heilo" [/SQL]


Question: Find all the instruments ever used by the musician with last name "Heilo"?

Answer: [SQL] SELECT instrument FROM instruments AS T1 JOIN Band AS T2 ON T1.bandmateid = T2.id WHERE T2.lastname = "Heilo" [/SQL]


Question: Which song has the most vocals?

Context: CREATE TABLE vocals (songid VARCHAR); CREATE TABLE songs (songid VARCHAR)

Answer: [SQL] SELECT title FROM vocals AS T1 JOIN songs AS T2 ON T1.songid = T2.songid GROUP BY T1.songid ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Which vocal type is the most frequently appearring type?

Context: CREATE TABLE vocals (TYPE VARCHAR)

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


Question: Which vocal type has the band mate with last name "Heilo" played the most?

Context: CREATE TABLE vocals (bandmate VARCHAR); CREATE TABLE band (id VARCHAR)

Answer: [SQL] SELECT TYPE FROM vocals AS T1 JOIN band AS T2 ON T1.bandmate = T2.id WHERE lastname = "Heilo" GROUP BY TYPE ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What are the vocal types used in song "Le Pop"?

Answer: [SQL] SELECT TYPE FROM vocals AS T1 JOIN songs AS T2 ON T1.songid = T2.songid WHERE title = "Le Pop" [/SQL]


Question: Find the number of vocal types used in song "Demon Kitty Rag"?

Answer: [SQL] SELECT COUNT(*) FROM vocals AS T1 JOIN songs AS T2 ON T1.songid = T2.songid WHERE title = "Demon Kitty Rag" [/SQL]


Question: How many songs have a lead vocal?

Answer: [SQL] SELECT COUNT(DISTINCT title) FROM vocals AS T1 JOIN songs AS T2 ON T1.songid = T2.songid WHERE TYPE = "lead" [/SQL]


Question: Which vocal type did the musician with first name "Solveig" played in the song with title "A Bar in Amsterdam"?

Context: CREATE TABLE vocals (songid VARCHAR, bandmate VARCHAR); CREATE TABLE band (id VARCHAR, firstname VARCHAR); CREATE TABLE songs (songid VARCHAR, title VARCHAR)

Answer: [SQL] SELECT TYPE FROM vocals AS T1 JOIN songs AS T2 ON T1.songid = T2.songid JOIN band AS T3 ON T1.bandmate = T3.id WHERE T3.firstname = "Solveig" AND T2.title = "A Bar In Amsterdam" [/SQL]


Question: Find all the songs that do not have a lead vocal.

Context: CREATE TABLE songs (title VARCHAR, songid VARCHAR); CREATE TABLE vocals (songid VARCHAR)

Answer: [SQL] SELECT DISTINCT title FROM vocals AS t1 JOIN songs AS t2 ON t1.songid = t2.songid EXCEPT SELECT t2.title FROM vocals AS t1 JOIN songs AS t2 ON t1.songid = t2.songid WHERE TYPE = "lead" [/SQL]


Question: Find all the vocal types.

Context: CREATE TABLE vocals (TYPE VARCHAR)

Answer: [SQL] SELECT DISTINCT TYPE FROM vocals [/SQL]


Question: What are the albums produced in year 2010?

Context: CREATE TABLE Albums (YEAR VARCHAR)

Answer: [SQL] SELECT * FROM Albums WHERE YEAR = 2010 [/SQL]


Question: Who performed the song named "Le Pop"?

Answer: [SQL] SELECT T2.firstname, T2.lastname FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id JOIN Songs AS T3 ON T3.SongId = T1.SongId WHERE T3.Title = "Le Pop" [/SQL]


Question: What instrument did the musician with last name "Heilo" use in the song "Badlands"?

Answer: [SQL] SELECT T4.instrument FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id JOIN Songs AS T3 ON T3.SongId = T1.SongId JOIN Instruments AS T4 ON T4.songid = T3.songid AND T4.bandmateid = T2.id WHERE T2.lastname = "Heilo" AND T3.title = "Badlands" [/SQL]


Question: How many instruments does the song "Badlands" use?

Answer: [SQL] SELECT COUNT(DISTINCT instrument) FROM instruments AS T1 JOIN songs AS T2 ON T1.songid = T2.songid WHERE title = "Badlands" [/SQL]


Question: What are the vocal types used in song "Badlands"?

Answer: [SQL] SELECT TYPE FROM vocals AS T1 JOIN songs AS T2 ON T1.songid = T2.songid WHERE title = "Badlands" [/SQL]


Question: Find the number of vocal types used in song "Le Pop"

Answer: [SQL] SELECT COUNT(*) FROM vocals AS T1 JOIN songs AS T2 ON T1.songid = T2.songid WHERE title = "Le Pop" [/SQL]


Question: How many songs have a shared vocal?

Answer: [SQL] SELECT COUNT(DISTINCT title) FROM vocals AS T1 JOIN songs AS T2 ON T1.songid = T2.songid WHERE TYPE = "shared" [/SQL]


Question: Find all the songs that do not have a back vocal.

Answer: [SQL] SELECT DISTINCT title FROM vocals AS t1 JOIN songs AS t2 ON t1.songid = t2.songid EXCEPT SELECT t2.title FROM vocals AS t1 JOIN songs AS t2 ON t1.songid = t2.songid WHERE TYPE = "back" [/SQL]


Question: Which vocal type has the band mate with first name "Solveig" played the most?

Answer: [SQL] SELECT TYPE FROM vocals AS T1 JOIN band AS T2 ON T1.bandmate = T2.id WHERE firstname = "Solveig" GROUP BY TYPE ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Which vocal type did the musician with last name "Heilo" played in the song with title "Der Kapitan"?

Context: CREATE TABLE band (id VARCHAR, lastname VARCHAR); CREATE TABLE vocals (songid VARCHAR, bandmate VARCHAR); CREATE TABLE songs (songid VARCHAR, title VARCHAR)

Answer: [SQL] SELECT TYPE FROM vocals AS T1 JOIN songs AS T2 ON T1.songid = T2.songid JOIN band AS T3 ON T1.bandmate = T3.id WHERE T3.lastname = "Heilo" AND T2.title = "Der Kapitan" [/SQL]


Question: Find the first name of the band mate that has performed in most songs.

Context: CREATE TABLE Songs (SongId VARCHAR); CREATE TABLE Band (firstname VARCHAR, id VARCHAR); CREATE TABLE Performance (bandmate VARCHAR)

Answer: [SQL] SELECT t2.firstname FROM Performance AS t1 JOIN Band AS t2 ON t1.bandmate = t2.id JOIN Songs AS T3 ON T3.SongId = T1.SongId GROUP BY firstname ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Which vocal type has the band mate with first name "Marianne" played the most?

Answer: [SQL] SELECT TYPE FROM vocals AS T1 JOIN band AS T2 ON T1.bandmate = T2.id WHERE firstname = "Marianne" GROUP BY TYPE ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Who is performing in the back stage position for the song "Der Kapitan"? Show the first name and last name.

Answer: [SQL] SELECT T2.firstname, T2.lastname FROM Performance AS T1 JOIN Band AS T2 ON T1.bandmate = T2.id JOIN Songs AS T3 ON T3.SongId = T1.SongId WHERE T3.Title = "Der Kapitan" AND T1.StagePosition = "back" [/SQL]


Question: What are the songs in album "A Kiss Before You Go: Live in Hamburg"?

Context: CREATE TABLE songs (title VARCHAR, songid VARCHAR); CREATE TABLE albums (aid VARCHAR, title VARCHAR); CREATE TABLE tracklists (albumid VARCHAR, songid VARCHAR)

Answer: [SQL] SELECT T3.title FROM albums AS T1 JOIN tracklists AS T2 ON T1.aid = T2.albumid JOIN songs AS T3 ON T2.songid = T3.songid WHERE T1.title = "A Kiss Before You Go: Live in Hamburg" [/SQL]


Question: What are all the songs in albums under label "Universal Music Group"?

Context: CREATE TABLE songs (title VARCHAR, songid VARCHAR); CREATE TABLE albums (aid VARCHAR); CREATE TABLE tracklists (albumid VARCHAR, songid VARCHAR)

Answer: [SQL] SELECT T3.title FROM albums AS T1 JOIN tracklists AS T2 ON T1.aid = T2.albumid JOIN songs AS T3 ON T2.songid = T3.songid WHERE t1.label = "Universal Music Group" [/SQL]


Question: Find the number of songs in all the studio albums.

Answer: [SQL] SELECT COUNT(DISTINCT T3.title) FROM albums AS T1 JOIN tracklists AS T2 ON T1.aid = T2.albumid JOIN songs AS T3 ON T2.songid = T3.songid WHERE t1.type = "Studio" [/SQL]


Question: Who is the founder of Sony?

Context: CREATE TABLE manufacturers (founder VARCHAR, name VARCHAR)

Answer: [SQL] SELECT founder FROM manufacturers WHERE name = 'Sony' [/SQL]


Question: Where is the headquarter of the company founded by James?

Context: CREATE TABLE manufacturers (headquarter VARCHAR, founder VARCHAR)

Answer: [SQL] SELECT headquarter FROM manufacturers WHERE founder = 'James' [/SQL]


Question: Find all manufacturers' names and their headquarters, sorted by the ones with highest revenue first.

Context: CREATE TABLE manufacturers (name VARCHAR, headquarter VARCHAR, revenue VARCHAR)

Answer: [SQL] SELECT name, headquarter FROM manufacturers ORDER BY revenue DESC [/SQL]


Question: What are the average, maximum and total revenues of all companies?

Context: CREATE TABLE manufacturers (revenue INTEGER)

Answer: [SQL] SELECT AVG(revenue), MAX(revenue), SUM(revenue) FROM manufacturers [/SQL]


Question: How many companies were created by Andy?

Context: CREATE TABLE manufacturers (founder VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM manufacturers WHERE founder = 'Andy' [/SQL]


Question: Find the total revenue created by the companies whose headquarter is located at Austin.

Context: CREATE TABLE manufacturers (revenue INTEGER, headquarter VARCHAR)

Answer: [SQL] SELECT SUM(revenue) FROM manufacturers WHERE headquarter = 'Austin' [/SQL]


Question: What are the different cities listed?

Context: CREATE TABLE manufacturers (headquarter VARCHAR)

Answer: [SQL] SELECT DISTINCT headquarter FROM manufacturers [/SQL]


Question: Find the number of manufactures that are based in Tokyo or Beijing.

Answer: [SQL] SELECT COUNT(*) FROM manufacturers WHERE headquarter = 'Tokyo' OR headquarter = 'Beijing' [/SQL]


Question: Find the founder of the company whose name begins with the letter 'S'.

Answer: [SQL] SELECT founder FROM manufacturers WHERE name LIKE 'S%' [/SQL]


Question: Find the name of companies whose revenue is between 100 and 150.

Context: CREATE TABLE manufacturers (name VARCHAR, revenue INTEGER)

Answer: [SQL] SELECT name FROM manufacturers WHERE revenue BETWEEN 100 AND 150 [/SQL]


Question: What is the total revenue of all companies whose main office is at Tokyo or Taiwan?

Context: CREATE TABLE manufacturers (revenue INTEGER, Headquarter VARCHAR)

Answer: [SQL] SELECT SUM(revenue) FROM manufacturers WHERE Headquarter = 'Tokyo' OR Headquarter = 'Taiwan' [/SQL]


Question: Find the name of product that is produced by both companies Creative Labs and Sony.

Context: CREATE TABLE manufacturers (code VARCHAR, name VARCHAR); CREATE TABLE products (name VARCHAR, Manufacturer VARCHAR)

Answer: [SQL] SELECT T1.name FROM products AS T1 JOIN manufacturers AS T2 ON T1.Manufacturer = T2.code WHERE T2.name = 'Creative Labs' INTERSECT SELECT T1.name FROM products AS T1 JOIN manufacturers AS T2 ON T1.Manufacturer = T2.code WHERE T2.name = 'Sony' [/SQL]


Question: Find the name, headquarter and founder of the manufacturer that has the highest revenue.

Context: CREATE TABLE manufacturers (name VARCHAR, headquarter VARCHAR, founder VARCHAR, revenue VARCHAR)

Answer: [SQL] SELECT name, headquarter, founder FROM manufacturers ORDER BY revenue DESC LIMIT 1 [/SQL]


Question: Find the name, headquarter and revenue of all manufacturers sorted by their revenue in the descending order.

Answer: [SQL] SELECT name, headquarter, revenue FROM manufacturers ORDER BY revenue DESC [/SQL]


Question: Find the name of companies whose revenue is greater than the average revenue of all companies.

Answer: [SQL] SELECT name FROM manufacturers WHERE revenue > (SELECT AVG(revenue) FROM manufacturers) [/SQL]


Question: Find the name of companies whose revenue is smaller than the revenue of all companies based in Austin.

Context: CREATE TABLE manufacturers (name VARCHAR, revenue INTEGER, headquarter VARCHAR)

Answer: [SQL] SELECT name FROM manufacturers WHERE revenue < (SELECT MIN(revenue) FROM manufacturers WHERE headquarter = 'Austin') [/SQL]


Question: Find the total revenue of companies whose revenue is larger than the revenue of some companies based in Austin.

Answer: [SQL] SELECT SUM(revenue) FROM manufacturers WHERE revenue > (SELECT MIN(revenue) FROM manufacturers WHERE headquarter = 'Austin') [/SQL]


Question: Find the total revenue of companies of each founder.

Context: CREATE TABLE manufacturers (founder VARCHAR, revenue INTEGER)

Answer: [SQL] SELECT SUM(revenue), founder FROM manufacturers GROUP BY founder [/SQL]


Question: Find the name and revenue of the company that earns the highest revenue in each city.

Context: CREATE TABLE manufacturers (name VARCHAR, Headquarter VARCHAR, revenue INTEGER)

Answer: [SQL] SELECT name, MAX(revenue), Headquarter FROM manufacturers GROUP BY Headquarter [/SQL]


Question: Find the total revenue for each manufacturer.

Answer: [SQL] SELECT SUM(revenue), name FROM manufacturers GROUP BY name [/SQL]


Question: Find the average prices of all products from each manufacture, and list each company's name.

Context: CREATE TABLE products (price INTEGER, Manufacturer VARCHAR); CREATE TABLE manufacturers (name VARCHAR, code VARCHAR)

Answer: [SQL] SELECT AVG(T1.price), T2.name FROM products AS T1 JOIN manufacturers AS T2 ON T1.Manufacturer = T2.code GROUP BY T2.name [/SQL]


Question: Find the number of different products that are produced by companies at different headquarter cities.

Context: CREATE TABLE manufacturers (Headquarter VARCHAR, code VARCHAR); CREATE TABLE products (name VARCHAR, Manufacturer VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT T1.name), T2.Headquarter FROM products AS T1 JOIN manufacturers AS T2 ON T1.Manufacturer = T2.code GROUP BY T2.Headquarter [/SQL]


Question: Find number of products which Sony does not make.

Context: CREATE TABLE manufacturers (code VARCHAR, name VARCHAR); CREATE TABLE products (name VARCHAR); CREATE TABLE products (name VARCHAR, Manufacturer VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT name) FROM products WHERE NOT name IN (SELECT T1.name FROM products AS T1 JOIN manufacturers AS T2 ON T1.Manufacturer = T2.code WHERE T2.name = 'Sony') [/SQL]


Question: Find the name of companies that do not make DVD drive.

Context: CREATE TABLE manufacturers (name VARCHAR, code VARCHAR); CREATE TABLE products (Manufacturer VARCHAR, name VARCHAR); CREATE TABLE manufacturers (name VARCHAR)

Answer: [SQL] SELECT name FROM manufacturers EXCEPT SELECT T2.name FROM products AS T1 JOIN manufacturers AS T2 ON T1.Manufacturer = T2.code WHERE T1.name = 'DVD drive' [/SQL]


Question: Find the number of products for each manufacturer, showing the name of each company.

Context: CREATE TABLE products (Manufacturer VARCHAR); CREATE TABLE manufacturers (name VARCHAR, code VARCHAR)

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


Question: Select the names of all the products in the store.

Context: CREATE TABLE Products (Name VARCHAR)

Answer: [SQL] SELECT Name FROM Products [/SQL]


Question: Select the names and the prices of all the products in the store.

Context: CREATE TABLE products (name VARCHAR, price VARCHAR)

Answer: [SQL] SELECT name, price FROM products [/SQL]


Question: Select the name of the products with a price less than or equal to $200.

Answer: [SQL] SELECT name FROM products WHERE price <= 200 [/SQL]


Question: Find all information of all the products with a price between $60 and $120.

Context: CREATE TABLE products (price INTEGER)

Answer: [SQL] SELECT * FROM products WHERE price BETWEEN 60 AND 120 [/SQL]


Question: Compute the average price of all the products.

Context: CREATE TABLE products (price INTEGER)

Answer: [SQL] SELECT AVG(price) FROM products [/SQL]


Question: Compute the average price of all products with manufacturer code equal to 2.

Context: CREATE TABLE products (price INTEGER, Manufacturer VARCHAR)

Answer: [SQL] SELECT AVG(price) FROM products WHERE Manufacturer = 2 [/SQL]


Question: Compute the number of products with a price larger than or equal to $180.

Context: CREATE TABLE products (price VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM products WHERE price >= 180 [/SQL]


Question: Select the name and price of all products with a price larger than or equal to $180, and sort first by price (in descending order), and then by name  (in ascending order).

Answer: [SQL] SELECT name, price FROM products WHERE price >= 180 ORDER BY price DESC, name [/SQL]


Question: Select all the data from the products and each product's manufacturer.

Context: CREATE TABLE products (manufacturer VARCHAR); CREATE TABLE Manufacturers (code VARCHAR)

Answer: [SQL] SELECT * FROM products AS T1 JOIN Manufacturers AS T2 ON T1.manufacturer = T2.code [/SQL]


Question: Select the average price of each manufacturer's products, showing only the manufacturer's code.

Context: CREATE TABLE Products (Manufacturer VARCHAR, Price INTEGER)

Answer: [SQL] SELECT AVG(Price), Manufacturer FROM Products GROUP BY Manufacturer [/SQL]


Question: Select the average price of each manufacturer's products, showing the manufacturer's name.

Context: CREATE TABLE Manufacturers (name VARCHAR, code VARCHAR); CREATE TABLE products (Price INTEGER, manufacturer VARCHAR)

Answer: [SQL] SELECT AVG(T1.Price), T2.name FROM products AS T1 JOIN Manufacturers AS T2 ON T1.manufacturer = T2.code GROUP BY T2.name [/SQL]


Question: Select the names of manufacturer whose products have an average price higher than or equal to $150.

Context: CREATE TABLE Manufacturers (name VARCHAR, code VARCHAR); CREATE TABLE products (Price INTEGER, manufacturer VARCHAR, price INTEGER)

Answer: [SQL] SELECT AVG(T1.Price), T2.name FROM products AS T1 JOIN Manufacturers AS T2 ON T1.manufacturer = T2.code GROUP BY T2.name HAVING AVG(T1.price) >= 150 [/SQL]


Question: Select the name and price of the cheapest product.

Context: CREATE TABLE Products (name VARCHAR, price VARCHAR)

Answer: [SQL] SELECT name, price FROM Products ORDER BY price LIMIT 1 [/SQL]


Question: Select the name of each manufacturer along with the name and price of its most expensive product.

Context: CREATE TABLE Manufacturers (name VARCHAR, code VARCHAR); CREATE TABLE products (Name VARCHAR, Price INTEGER, manufacturer VARCHAR)

Answer: [SQL] SELECT T1.Name, MAX(T1.Price), T2.name FROM products AS T1 JOIN Manufacturers AS T2 ON T1.manufacturer = T2.code GROUP BY T2.name [/SQL]


Question: Select the code of the product that is cheapest in each product category.

Context: CREATE TABLE products (code VARCHAR, name VARCHAR, price INTEGER)

Answer: [SQL] SELECT code, name, MIN(price) FROM products GROUP BY name [/SQL]


Question: What is the id of the problem log that is created most recently?

Context: CREATE TABLE problem_log (problem_log_id VARCHAR, log_entry_date VARCHAR)

Answer: [SQL] SELECT problem_log_id FROM problem_log ORDER BY log_entry_date DESC LIMIT 1 [/SQL]


Question: What is the oldest log id and its corresponding problem id?

Context: CREATE TABLE problem_log (problem_log_id VARCHAR, problem_id VARCHAR, log_entry_date VARCHAR)

Answer: [SQL] SELECT problem_log_id, problem_id FROM problem_log ORDER BY log_entry_date LIMIT 1 [/SQL]


Question: Find all the ids and dates of the logs for the problem whose id is 10.

Context: CREATE TABLE problem_log (problem_log_id VARCHAR, log_entry_date VARCHAR, problem_id VARCHAR)

Answer: [SQL] SELECT problem_log_id, log_entry_date FROM problem_log WHERE problem_id = 10 [/SQL]


Question: List all the log ids and their descriptions from the problem logs.

Context: CREATE TABLE problem_log (problem_log_id VARCHAR, log_entry_description VARCHAR)

Answer: [SQL] SELECT problem_log_id, log_entry_description FROM problem_log [/SQL]


Question: List the first and last names of all distinct staff members who are assigned to the problem whose id is 1.

Context: CREATE TABLE problem_log (assigned_to_staff_id VARCHAR, problem_id VARCHAR); CREATE TABLE staff (staff_id VARCHAR)

Answer: [SQL] SELECT DISTINCT staff_first_name, staff_last_name FROM staff AS T1 JOIN problem_log AS T2 ON T1.staff_id = T2.assigned_to_staff_id WHERE T2.problem_id = 1 [/SQL]


Question: List the problem id and log id which are assigned to the staff named Rylan Homenick.

Context: CREATE TABLE problem_log (problem_id VARCHAR, problem_log_id VARCHAR, assigned_to_staff_id VARCHAR); CREATE TABLE staff (staff_id VARCHAR, staff_first_name VARCHAR, staff_last_name VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.problem_id, T2.problem_log_id FROM staff AS T1 JOIN problem_log AS T2 ON T1.staff_id = T2.assigned_to_staff_id WHERE T1.staff_first_name = "Rylan" AND T1.staff_last_name = "Homenick" [/SQL]


Question: How many problems are there for product voluptatem?

Context: CREATE TABLE problems (product_id VARCHAR); CREATE TABLE product (product_id VARCHAR, product_name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM product AS T1 JOIN problems AS T2 ON T1.product_id = T2.product_id WHERE T1.product_name = "voluptatem" [/SQL]


Question: How many problems does the product with the most problems have? List the number of the problems and product name.

Context: CREATE TABLE problems (product_id VARCHAR); CREATE TABLE product (product_name VARCHAR, product_id VARCHAR)

Answer: [SQL] SELECT COUNT(*), T1.product_name FROM product AS T1 JOIN problems AS T2 ON T1.product_id = T2.product_id GROUP BY T1.product_name ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Give me a list of descriptions of the problems that are reported by the staff whose first name is Christop.

Context: CREATE TABLE staff (staff_id VARCHAR, staff_first_name VARCHAR); CREATE TABLE problems (problem_description VARCHAR, reported_by_staff_id VARCHAR)

Answer: [SQL] SELECT T1.problem_description FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Christop" [/SQL]


Question: Find the ids of the problems that are reported by the staff whose last name is Bosco.

Context: CREATE TABLE problems (problem_id VARCHAR, reported_by_staff_id VARCHAR); CREATE TABLE staff (staff_id VARCHAR, staff_last_name VARCHAR)

Answer: [SQL] SELECT T1.problem_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_last_name = "Bosco" [/SQL]


Question: What are the ids of the problems which are reported after 1978-06-26?

Context: CREATE TABLE problems (problem_id VARCHAR, date_problem_reported INTEGER)

Answer: [SQL] SELECT problem_id FROM problems WHERE date_problem_reported > "1978-06-26" [/SQL]


Question: What are the ids of the problems which are reported before 1978-06-26?

Answer: [SQL] SELECT problem_id FROM problems WHERE date_problem_reported < "1978-06-26" [/SQL]


Question: For each product which has problems, what are the number of problems and the product id?

Context: CREATE TABLE problems (product_id VARCHAR); CREATE TABLE product (product_id VARCHAR)

Answer: [SQL] SELECT COUNT(*), T2.product_id FROM problems AS T1 JOIN product AS T2 ON T1.product_id = T2.product_id GROUP BY T2.product_id [/SQL]


Question: For each product that has problems, find the number of problems reported after 1986-11-13 and the product id?

Context: CREATE TABLE product (product_id VARCHAR); CREATE TABLE problems (product_id VARCHAR, date_problem_reported INTEGER)

Answer: [SQL] SELECT COUNT(*), T2.product_id FROM problems AS T1 JOIN product AS T2 ON T1.product_id = T2.product_id WHERE T1.date_problem_reported > "1986-11-13" GROUP BY T2.product_id [/SQL]


Question: List the names of all the distinct product names in alphabetical order?

Context: CREATE TABLE product (product_name VARCHAR)

Answer: [SQL] SELECT DISTINCT product_name FROM product ORDER BY product_name [/SQL]


Question: List all the distinct product names ordered by product id?

Context: CREATE TABLE product (product_name VARCHAR, product_id VARCHAR)

Answer: [SQL] SELECT DISTINCT product_name FROM product ORDER BY product_id [/SQL]


Question: What are the id of problems reported by the staff named Dameon Frami or Jolie Weber?

Context: CREATE TABLE staff (staff_id VARCHAR, staff_first_name VARCHAR, staff_last_name VARCHAR); CREATE TABLE problems (reported_by_staff_id VARCHAR)

Answer: [SQL] SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Dameon" AND T2.staff_last_name = "Frami" UNION SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Jolie" AND T2.staff_last_name = "Weber" [/SQL]


Question: What are the product ids for the problems reported by Christop Berge with closure authorised by Ashley Medhurst?

Context: CREATE TABLE problems (reported_by_staff_id VARCHAR, closure_authorised_by_staff_id VARCHAR); CREATE TABLE staff (staff_id VARCHAR, staff_first_name VARCHAR, staff_last_name VARCHAR)

Answer: [SQL] SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Christop" AND T2.staff_last_name = "Berge" INTERSECT SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.closure_authorised_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Ashley" AND T2.staff_last_name = "Medhurst" [/SQL]


Question: What are the ids of the problems reported before the date of any problem reported by Lysanne Turcotte?

Context: CREATE TABLE problems (problem_id VARCHAR, reported_by_staff_id VARCHAR); CREATE TABLE staff (staff_id VARCHAR, staff_first_name VARCHAR, staff_last_name VARCHAR); CREATE TABLE problems (reported_by_staff_id VARCHAR); CREATE TABLE staff (staff_id VARCHAR)

Answer: [SQL] SELECT T1.problem_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE date_problem_reported < (SELECT MIN(date_problem_reported) FROM problems AS T3 JOIN staff AS T4 ON T3.reported_by_staff_id = T4.staff_id WHERE T4.staff_first_name = "Lysanne" AND T4.staff_last_name = "Turcotte") [/SQL]


Question: What are the ids of the problems reported after the date of any problems reported by Rylan Homenick?

Answer: [SQL] SELECT T1.problem_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE date_problem_reported > (SELECT MAX(date_problem_reported) FROM problems AS T3 JOIN staff AS T4 ON T3.reported_by_staff_id = T4.staff_id WHERE T4.staff_first_name = "Rylan" AND T4.staff_last_name = "Homenick") [/SQL]


Question: Find the top 3 products which have the largest number of problems?

Answer: [SQL] SELECT T2.product_name FROM problems AS T1 JOIN product AS T2 ON T1.product_id = T2.product_id GROUP BY T2.product_name ORDER BY COUNT(*) DESC LIMIT 3 [/SQL]


Question: List the ids of the problems from the product "voluptatem" that are reported after 1995?

Context: CREATE TABLE problems (problem_id VARCHAR, product_id VARCHAR, date_problem_reported VARCHAR); CREATE TABLE product (product_id VARCHAR, product_name VARCHAR)

Answer: [SQL] SELECT T1.problem_id FROM problems AS T1 JOIN product AS T2 ON T1.product_id = T2.product_id WHERE T2.product_name = "voluptatem" AND T1.date_problem_reported > "1995" [/SQL]


Question: Find the first and last name of the staff members who reported problems from the product "rem" but not "aut"?

Context: CREATE TABLE product (product_name VARCHAR, product_id VARCHAR); CREATE TABLE staff (staff_first_name VARCHAR, staff_last_name VARCHAR, staff_id VARCHAR); CREATE TABLE problems (product_id VARCHAR, reported_by_staff_id VARCHAR)

Answer: [SQL] SELECT T3.staff_first_name, T3.staff_last_name FROM problems AS T1 JOIN product AS T2 JOIN staff AS T3 ON T1.product_id = T2.product_id AND T1.reported_by_staff_id = T3.staff_id WHERE T2.product_name = "rem" EXCEPT SELECT T3.staff_first_name, T3.staff_last_name FROM problems AS T1 JOIN product AS T2 JOIN staff AS T3 ON T1.product_id = T2.product_id AND T1.reported_by_staff_id = T3.staff_id WHERE T2.product_name = "aut" [/SQL]


Question: Find the products which have problems reported by both Lacey Bosco and Kenton Champlin?

Context: CREATE TABLE product (product_name VARCHAR, product_id VARCHAR); CREATE TABLE staff (staff_id VARCHAR, staff_first_name VARCHAR, staff_last_name VARCHAR); CREATE TABLE problems (product_id VARCHAR, reported_by_staff_id VARCHAR)

Answer: [SQL] SELECT T2.product_name FROM problems AS T1 JOIN product AS T2 JOIN staff AS T3 ON T1.product_id = T2.product_id AND T1.reported_by_staff_id = T3.staff_id WHERE T3.staff_first_name = "Lacey" AND T3.staff_last_name = "Bosco" INTERSECT SELECT T2.product_name FROM problems AS T1 JOIN product AS T2 JOIN staff AS T3 ON T1.product_id = T2.product_id AND T1.reported_by_staff_id = T3.staff_id WHERE T3.staff_first_name = "Kenton" AND T3.staff_last_name = "Champlin" [/SQL]


Question: How many branches where have more than average number of memberships are there?

Context: CREATE TABLE branch (membership_amount INTEGER)

Answer: [SQL] SELECT COUNT(*) FROM branch WHERE membership_amount > (SELECT AVG(membership_amount) FROM branch) [/SQL]


Question: Show name, address road, and city for all branches sorted by open year.

Context: CREATE TABLE branch (name VARCHAR, address_road VARCHAR, city VARCHAR, open_year VARCHAR)

Answer: [SQL] SELECT name, address_road, city FROM branch ORDER BY open_year [/SQL]


Question: What are names for top three branches with most number of membership?

Context: CREATE TABLE branch (name VARCHAR, membership_amount VARCHAR)

Answer: [SQL] SELECT name FROM branch ORDER BY membership_amount DESC LIMIT 3 [/SQL]


Question: Show all distinct city where branches with at least 100 memberships are located.

Context: CREATE TABLE branch (city VARCHAR, membership_amount VARCHAR)

Answer: [SQL] SELECT DISTINCT city FROM branch WHERE membership_amount >= 100 [/SQL]


Question: List all open years when at least two shops are opened.

Context: CREATE TABLE branch (open_year VARCHAR)

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


Question: Show minimum and maximum amount of memberships for all branches opened in 2011 or located at city London.

Context: CREATE TABLE branch (membership_amount INTEGER, open_year VARCHAR, city VARCHAR)

Answer: [SQL] SELECT MIN(membership_amount), MAX(membership_amount) FROM branch WHERE open_year = 2011 OR city = 'London' [/SQL]


Question: Show the city and the number of branches opened before 2010 for each city.

Context: CREATE TABLE branch (city VARCHAR, open_year INTEGER)

Answer: [SQL] SELECT city, COUNT(*) FROM branch WHERE open_year < 2010 GROUP BY city [/SQL]


Question: How many different levels do members have?

Context: CREATE TABLE member (LEVEL VARCHAR)

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


Question: Show card number, name, and hometown for all members in a descending order of level.

Context: CREATE TABLE member (card_number VARCHAR, name VARCHAR, hometown VARCHAR, LEVEL VARCHAR)

Answer: [SQL] SELECT card_number, name, hometown FROM member ORDER BY LEVEL DESC [/SQL]


Question: Show the membership level with most number of members.

Context: CREATE TABLE member (LEVEL VARCHAR)

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


Question: Show all member names and registered branch names sorted by register year.

Context: CREATE TABLE member (name VARCHAR, member_id VARCHAR); CREATE TABLE membership_register_branch (branch_id VARCHAR, member_id VARCHAR, register_year VARCHAR); CREATE TABLE branch (name VARCHAR, branch_id VARCHAR)

Answer: [SQL] SELECT T3.name, T2.name FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id JOIN member AS T3 ON T1.member_id = T3.member_id ORDER BY T1.register_year [/SQL]


Question: Show all branch names with the number of members in each branch registered after 2015.

Context: CREATE TABLE branch (name VARCHAR, branch_id VARCHAR); CREATE TABLE membership_register_branch (branch_id VARCHAR, register_year INTEGER)

Answer: [SQL] SELECT T2.name, COUNT(*) FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id WHERE T1.register_year > 2015 GROUP BY T2.branch_id [/SQL]


Question: Show member names without any registered branch.

Context: CREATE TABLE member (name VARCHAR, member_id VARCHAR); CREATE TABLE membership_register_branch (name VARCHAR, member_id VARCHAR)

Answer: [SQL] SELECT name FROM member WHERE NOT member_id IN (SELECT member_id FROM membership_register_branch) [/SQL]


Question: List the branch name and city without any registered members.

Context: CREATE TABLE membership_register_branch (name VARCHAR, city VARCHAR, branch_id VARCHAR); CREATE TABLE branch (name VARCHAR, city VARCHAR, branch_id VARCHAR)

Answer: [SQL] SELECT name, city FROM branch WHERE NOT branch_id IN (SELECT branch_id FROM membership_register_branch) [/SQL]


Question: What is the name and open year for the branch with most number of memberships registered in 2016?

Context: CREATE TABLE membership_register_branch (branch_id VARCHAR, register_year VARCHAR); CREATE TABLE branch (name VARCHAR, open_year VARCHAR, branch_id VARCHAR)

Answer: [SQL] SELECT T2.name, T2.open_year FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id WHERE T1.register_year = 2016 GROUP BY T2.branch_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the member name and hometown who registered a branch in 2016.

Context: CREATE TABLE member (name VARCHAR, hometown VARCHAR, member_id VARCHAR); CREATE TABLE membership_register_branch (member_id VARCHAR, register_year VARCHAR)

Answer: [SQL] SELECT T2.name, T2.hometown FROM membership_register_branch AS T1 JOIN member AS T2 ON T1.member_id = T2.member_id WHERE T1.register_year = 2016 [/SQL]


Question: Show all city with a branch opened in 2001 and a branch with more than 100 membership.

Context: CREATE TABLE branch (city VARCHAR, open_year VARCHAR, membership_amount VARCHAR)

Answer: [SQL] SELECT city FROM branch WHERE open_year = 2001 AND membership_amount > 100 [/SQL]


Question: Show all cities without a branch having more than 100 memberships.

Context: CREATE TABLE branch (city VARCHAR, membership_amount INTEGER)

Answer: [SQL] SELECT city FROM branch EXCEPT SELECT city FROM branch WHERE membership_amount > 100 [/SQL]


Question: What is the sum of total pounds of purchase in year 2018 for all branches in London?

Context: CREATE TABLE purchase (branch_id VARCHAR, year VARCHAR); CREATE TABLE branch (branch_id VARCHAR, city VARCHAR)

Answer: [SQL] SELECT SUM(total_pounds) FROM purchase AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id WHERE T2.city = 'London' AND T1.year = 2018 [/SQL]


Question: What is the total number of purchases for members with level 6?

Context: CREATE TABLE member (member_id VARCHAR, level VARCHAR); CREATE TABLE purchase (member_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM purchase AS T1 JOIN member AS T2 ON T1.member_id = T2.member_id WHERE T2.level = 6 [/SQL]


Question: Find the name of branches where have some members whose hometown is in Louisville, Kentucky and some in Hiram, Georgia.

Context: CREATE TABLE member (member_id VARCHAR, Hometown VARCHAR); CREATE TABLE branch (name VARCHAR, branch_id VARCHAR); CREATE TABLE membership_register_branch (branch_id VARCHAR, member_id VARCHAR)

Answer: [SQL] SELECT T2.name FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id JOIN member AS T3 ON T1.member_id = T3.member_id WHERE T3.Hometown = 'Louisville ,  Kentucky' INTERSECT SELECT T2.name FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id JOIN member AS T3 ON T1.member_id = T3.member_id WHERE T3.Hometown = 'Hiram ,  Georgia' [/SQL]


Question: list the card number of all members whose hometown address includes word "Kentucky".

Context: CREATE TABLE member (card_number VARCHAR, Hometown VARCHAR)

Answer: [SQL] SELECT card_number FROM member WHERE Hometown LIKE "%Kentucky%" [/SQL]


Question: Find the number of students in total.

Context: CREATE TABLE STUDENT (Id VARCHAR)

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


Question: Find the number of voting records in total.

Context: CREATE TABLE VOTING_RECORD (Id VARCHAR)

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


Question: Find the distinct number of president votes.

Context: CREATE TABLE VOTING_RECORD (President_Vote VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT President_Vote) FROM VOTING_RECORD [/SQL]


Question: Find the maximum age of all the students.

Context: CREATE TABLE STUDENT (Age INTEGER)

Answer: [SQL] SELECT MAX(Age) FROM STUDENT [/SQL]


Question: Find the last names of students with major 50.

Context: CREATE TABLE STUDENT (LName VARCHAR, Major VARCHAR)

Answer: [SQL] SELECT LName FROM STUDENT WHERE Major = 50 [/SQL]


Question: Find the first names of students with age above 22.

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

Answer: [SQL] SELECT Fname FROM STUDENT WHERE Age > 22 [/SQL]


Question: What are the majors of male (sex is M) students?

Context: CREATE TABLE STUDENT (Major VARCHAR, Sex VARCHAR)

Answer: [SQL] SELECT Major FROM STUDENT WHERE Sex = "M" [/SQL]


Question: What is the average age of female (sex is F) students?

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

Answer: [SQL] SELECT AVG(Age) FROM STUDENT WHERE Sex = "F" [/SQL]


Question: What are the maximum and minimum age of students with major 600?

Context: CREATE TABLE STUDENT (Age INTEGER, Major VARCHAR)

Answer: [SQL] SELECT MAX(Age), MIN(Age) FROM STUDENT WHERE Major = 600 [/SQL]


Question: Who are the advisors for students that live in a city with city code "BAL"?

Context: CREATE TABLE STUDENT (Advisor VARCHAR, city_code VARCHAR)

Answer: [SQL] SELECT Advisor FROM STUDENT WHERE city_code = "BAL" [/SQL]


Question: What are the distinct secretary votes in the fall election cycle?

Context: CREATE TABLE VOTING_RECORD (Secretary_Vote VARCHAR, ELECTION_CYCLE VARCHAR)

Answer: [SQL] SELECT DISTINCT Secretary_Vote FROM VOTING_RECORD WHERE ELECTION_CYCLE = "Fall" [/SQL]


Question: What are the distinct president votes on 08/30/2015?

Context: CREATE TABLE VOTING_RECORD (PRESIDENT_Vote VARCHAR, Registration_Date VARCHAR)

Answer: [SQL] SELECT DISTINCT PRESIDENT_Vote FROM VOTING_RECORD WHERE Registration_Date = "08/30/2015" [/SQL]


Question: Report the distinct registration date and the election cycle.

Context: CREATE TABLE VOTING_RECORD (Registration_Date VARCHAR, Election_Cycle VARCHAR)

Answer: [SQL] SELECT DISTINCT Registration_Date, Election_Cycle FROM VOTING_RECORD [/SQL]


Question: Report the distinct president vote and the vice president vote.

Context: CREATE TABLE VOTING_RECORD (President_Vote VARCHAR, VICE_President_Vote VARCHAR)

Answer: [SQL] SELECT DISTINCT President_Vote, VICE_President_Vote FROM VOTING_RECORD [/SQL]


Question: Find the distinct last names of the students who have class president votes.

Context: CREATE TABLE STUDENT (LName VARCHAR, StuID VARCHAR); CREATE TABLE VOTING_RECORD (CLASS_President_VOTE VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = T2.CLASS_President_VOTE [/SQL]


Question: Find the distinct first names of the students who have class senator votes.

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

Answer: [SQL] SELECT DISTINCT T1.Fname FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = T2.CLASS_Senator_VOTE [/SQL]


Question: Find the distinct ages of students who have secretary votes in the fall election cycle.

Context: CREATE TABLE VOTING_RECORD (Secretary_Vote VARCHAR, Election_Cycle VARCHAR); CREATE TABLE STUDENT (Age VARCHAR, StuID VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.Age FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = T2.Secretary_Vote WHERE T2.Election_Cycle = "Fall" [/SQL]


Question: Find the distinct Advisor of students who have treasurer votes in the spring election cycle.

Context: CREATE TABLE STUDENT (Advisor VARCHAR, StuID VARCHAR); CREATE TABLE VOTING_RECORD (Treasurer_Vote VARCHAR, Election_Cycle VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.Advisor FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = T2.Treasurer_Vote WHERE T2.Election_Cycle = "Spring" [/SQL]


Question: Find the distinct majors of students who have treasurer votes.

Context: CREATE TABLE VOTING_RECORD (Treasurer_Vote VARCHAR); CREATE TABLE STUDENT (Major VARCHAR, StuID VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.Major FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = T2.Treasurer_Vote [/SQL]


Question: Find the first and last names of all the female (sex is F) students who have president votes.

Context: CREATE TABLE STUDENT (Fname VARCHAR, LName VARCHAR, StuID VARCHAR, sex VARCHAR); CREATE TABLE VOTING_RECORD (President_VOTE VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.Fname, T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = T2.President_VOTE WHERE T1.sex = "F" [/SQL]


Question: Find the first and last name of all the students of age 18 who have vice president votes.

Context: CREATE TABLE STUDENT (Fname VARCHAR, LName VARCHAR, StuID VARCHAR, age VARCHAR); CREATE TABLE VOTING_RECORD (VICE_President_VOTE VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.Fname, T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = T2.VICE_President_VOTE WHERE T1.age = 18 [/SQL]


Question: How many male (sex is M) students have class senator votes in the fall election cycle?

Context: CREATE TABLE VOTING_RECORD (Election_Cycle VARCHAR); CREATE TABLE STUDENT (StuID VARCHAR, Sex VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = Class_Senator_Vote WHERE T1.Sex = "M" AND T2.Election_Cycle = "Fall" [/SQL]


Question: Find the number of students whose city code is NYC and who have class senator votes in the spring election cycle.

Context: CREATE TABLE STUDENT (StuID VARCHAR, city_code VARCHAR); CREATE TABLE VOTING_RECORD (Election_Cycle VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = Class_Senator_Vote WHERE T1.city_code = "NYC" AND T2.Election_Cycle = "Spring" [/SQL]


Question: Find the average age of students who live in the city with code "NYC" and have secretary votes in the spring election cycle.

Context: CREATE TABLE STUDENT (Age INTEGER, StuID VARCHAR, city_code VARCHAR); CREATE TABLE VOTING_RECORD (Election_Cycle VARCHAR)

Answer: [SQL] SELECT AVG(T1.Age) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = SECRETARY_Vote WHERE T1.city_code = "NYC" AND T2.Election_Cycle = "Spring" [/SQL]


Question: Find the average age of female (sex is F) students who have secretary votes in the spring election cycle.

Context: CREATE TABLE STUDENT (Age INTEGER, StuID VARCHAR, Sex VARCHAR); CREATE TABLE VOTING_RECORD (Election_Cycle VARCHAR)

Answer: [SQL] SELECT AVG(T1.Age) FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = SECRETARY_Vote WHERE T1.Sex = "F" AND T2.Election_Cycle = "Spring" [/SQL]


Question: Find the distinct first names of all the students who have vice president votes and whose city code is not PIT.

Context: CREATE TABLE STUDENT (Fname VARCHAR, city_code VARCHAR); CREATE TABLE STUDENT (Fname VARCHAR, StuID VARCHAR); CREATE TABLE VOTING_RECORD (VICE_PRESIDENT_Vote VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.Fname FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = T2.VICE_PRESIDENT_Vote EXCEPT SELECT DISTINCT Fname FROM STUDENT WHERE city_code = "PIT" [/SQL]


Question: Find the distinct last names of all the students who have president votes and whose advisor is not 2192.

Context: CREATE TABLE STUDENT (LName VARCHAR, PRESIDENT_Vote VARCHAR, Advisor VARCHAR); CREATE TABLE STUDENT (LName VARCHAR, StuID VARCHAR); CREATE TABLE VOTING_RECORD (Id VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = PRESIDENT_Vote EXCEPT SELECT DISTINCT LName FROM STUDENT WHERE Advisor = "2192" [/SQL]


Question: Find the distinct last names of all the students who have president votes and whose advisor is 8741.

Answer: [SQL] SELECT DISTINCT T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = PRESIDENT_Vote INTERSECT SELECT DISTINCT LName FROM STUDENT WHERE Advisor = "8741" [/SQL]


Question: For each advisor, report the total number of students advised by him or her.

Context: CREATE TABLE STUDENT (Advisor VARCHAR)

Answer: [SQL] SELECT Advisor, COUNT(*) FROM STUDENT GROUP BY Advisor [/SQL]


Question: Report all advisors that advise more than 2 students.

Context: CREATE TABLE STUDENT (Advisor VARCHAR)

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


Question: Report all majors that have less than 3 students.

Context: CREATE TABLE STUDENT (Major VARCHAR)

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


Question: For each election cycle, report the number of voting records.

Context: CREATE TABLE VOTING_RECORD (Election_Cycle VARCHAR)

Answer: [SQL] SELECT Election_Cycle, COUNT(*) FROM VOTING_RECORD GROUP BY Election_Cycle [/SQL]


Question: Which major has the most students?

Context: CREATE TABLE STUDENT (Major VARCHAR, major VARCHAR)

Answer: [SQL] SELECT Major FROM STUDENT GROUP BY major ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the most common major among female (sex is F) students?

Context: CREATE TABLE STUDENT (Major VARCHAR, major VARCHAR, Sex VARCHAR)

Answer: [SQL] SELECT Major FROM STUDENT WHERE Sex = "F" GROUP BY major ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the city_code of the city that the most students live in?

Context: CREATE TABLE STUDENT (city_code VARCHAR)

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


Question: How many products are there?

Context: CREATE TABLE products (Id VARCHAR)

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


Question: How many colors are there?

Context: CREATE TABLE ref_colors (Id VARCHAR)

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


Question: How many characteristics are there?

Context: CREATE TABLE CHARACTERISTICS (Id VARCHAR)

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


Question: What are the names and buying prices of all the products?

Context: CREATE TABLE products (product_name VARCHAR, typical_buying_price VARCHAR)

Answer: [SQL] SELECT product_name, typical_buying_price FROM products [/SQL]


Question: List the description of all the colors.

Context: CREATE TABLE ref_colors (color_description VARCHAR)

Answer: [SQL] SELECT color_description FROM ref_colors [/SQL]


Question: Find the names of all the product characteristics.

Context: CREATE TABLE CHARACTERISTICS (characteristic_name VARCHAR)

Answer: [SQL] SELECT DISTINCT characteristic_name FROM CHARACTERISTICS [/SQL]


Question: What are the names of products with category "Spices"?

Context: CREATE TABLE products (product_name VARCHAR, product_category_code VARCHAR)

Answer: [SQL] SELECT product_name FROM products WHERE product_category_code = "Spices" [/SQL]


Question: List the names, color descriptions and product descriptions of products with category "Herbs".

Context: CREATE TABLE Ref_colors (color_description VARCHAR, color_code VARCHAR); CREATE TABLE products (product_name VARCHAR, product_description VARCHAR, color_code VARCHAR)

Answer: [SQL] SELECT T1.product_name, T2.color_description, T1.product_description FROM products AS T1 JOIN Ref_colors AS T2 ON T1.color_code = T2.color_code WHERE product_category_code = "Herbs" [/SQL]


Question: How many products are there under the category "Seeds"?

Context: CREATE TABLE products (product_category_code VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM products WHERE product_category_code = "Seeds" [/SQL]


Question: Find the number of products with category "Spices" and typically sold above 1000.

Context: CREATE TABLE products (product_category_code VARCHAR, typical_buying_price VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM products WHERE product_category_code = "Spices" AND typical_buying_price > 1000 [/SQL]


Question: What is the category and typical buying price  of the product with name "cumin"?

Context: CREATE TABLE products (product_category_code VARCHAR, typical_buying_price VARCHAR, product_name VARCHAR)

Answer: [SQL] SELECT product_category_code, typical_buying_price FROM products WHERE product_name = "cumin" [/SQL]


Question: Which category does the product named "flax" belong to?

Context: CREATE TABLE products (product_category_code VARCHAR, product_name VARCHAR)

Answer: [SQL] SELECT product_category_code FROM products WHERE product_name = "flax" [/SQL]


Question: What is the name of the product with the color description 'yellow'?

Context: CREATE TABLE ref_colors (color_code VARCHAR, color_description VARCHAR); CREATE TABLE products (product_name VARCHAR, color_code VARCHAR)

Answer: [SQL] SELECT T1.product_name FROM products AS T1 JOIN ref_colors AS T2 ON T1.color_code = T2.color_code WHERE T2.color_description = 'yellow' [/SQL]


Question: Find the category descriptions of the products whose descriptions include letter 't'.

Context: CREATE TABLE ref_product_categories (product_category_description VARCHAR, product_category_code VARCHAR); CREATE TABLE products (product_category_code VARCHAR, product_description VARCHAR)

Answer: [SQL] SELECT T1.product_category_description FROM ref_product_categories AS T1 JOIN products AS T2 ON T1.product_category_code = T2.product_category_code WHERE T2.product_description LIKE '%t%' [/SQL]


Question: What is the color description of the product with name "catnip"?

Context: CREATE TABLE products (color_code VARCHAR, product_name VARCHAR); CREATE TABLE ref_colors (color_description VARCHAR, color_code VARCHAR)

Answer: [SQL] SELECT t2.color_description FROM products AS t1 JOIN ref_colors AS t2 ON t1.color_code = t2.color_code WHERE t1.product_name = "catnip" [/SQL]


Question: What is the color code and description of the product named "chervil"?

Answer: [SQL] SELECT t1.color_code, t2.color_description FROM products AS t1 JOIN ref_colors AS t2 ON t1.color_code = t2.color_code WHERE t1.product_name = "chervil" [/SQL]


Question: Find the id and color description of the products with at least 2 characteristics.

Context: CREATE TABLE product_characteristics (product_id VARCHAR); CREATE TABLE ref_colors (color_description VARCHAR, color_code VARCHAR); CREATE TABLE products (product_id VARCHAR, color_code VARCHAR)

Answer: [SQL] SELECT t1.product_id, t2.color_description FROM products AS t1 JOIN ref_colors AS t2 ON t1.color_code = t2.color_code JOIN product_characteristics AS t3 ON t1.product_id = t3.product_id GROUP BY t1.product_id HAVING COUNT(*) >= 2 [/SQL]


Question: List all the product names with the color description "white".

Answer: [SQL] SELECT t1.product_name FROM products AS t1 JOIN ref_colors AS t2 ON t1.color_code = t2.color_code WHERE t2.color_description = "white" [/SQL]


Question: What are the name and typical buying and selling prices of the products that have color described as "yellow"?

Context: CREATE TABLE ref_colors (color_code VARCHAR, color_description VARCHAR); CREATE TABLE products (product_name VARCHAR, typical_buying_price VARCHAR, typical_selling_price VARCHAR, color_code VARCHAR)

Answer: [SQL] SELECT t1.product_name, t1.typical_buying_price, t1.typical_selling_price FROM products AS t1 JOIN ref_colors AS t2 ON t1.color_code = t2.color_code WHERE t2.color_description = "yellow" [/SQL]


Question: How many characteristics does the product named "sesame" have?

Context: CREATE TABLE product_characteristics (product_id VARCHAR); CREATE TABLE products (product_id VARCHAR, product_name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id WHERE t1.product_name = "sesame" [/SQL]


Question: How many distinct characteristic names does the product "cumin" have?

Context: CREATE TABLE CHARACTERISTICS (characteristic_name VARCHAR, characteristic_id VARCHAR); CREATE TABLE products (product_id VARCHAR, product_name VARCHAR); CREATE TABLE product_characteristics (product_id VARCHAR, characteristic_id VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT t3.characteristic_name) FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id WHERE t1.product_name = "sesame" [/SQL]


Question: What are all the characteristic names of product "sesame"?

Answer: [SQL] SELECT t3.characteristic_name FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id WHERE t1.product_name = "sesame" [/SQL]


Question: List all the characteristic names and data types of product "cumin".

Context: CREATE TABLE CHARACTERISTICS (characteristic_name VARCHAR, characteristic_data_type VARCHAR, characteristic_id VARCHAR); CREATE TABLE products (product_id VARCHAR, product_name VARCHAR); CREATE TABLE product_characteristics (product_id VARCHAR, characteristic_id VARCHAR)

Answer: [SQL] SELECT t3.characteristic_name, t3.characteristic_data_type FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id WHERE t1.product_name = "cumin" [/SQL]


Question: List all characteristics of product named "sesame" with type code "Grade".

Context: CREATE TABLE CHARACTERISTICS (characteristic_name VARCHAR, characteristic_id VARCHAR, characteristic_type_code VARCHAR); CREATE TABLE products (product_id VARCHAR, product_name VARCHAR); CREATE TABLE product_characteristics (product_id VARCHAR, characteristic_id VARCHAR)

Answer: [SQL] SELECT t3.characteristic_name FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id WHERE t1.product_name = "sesame" AND t3.characteristic_type_code = "Grade" [/SQL]


Question: How many characteristics does the product named "laurel" have?

Context: CREATE TABLE CHARACTERISTICS (characteristic_id VARCHAR); CREATE TABLE products (product_id VARCHAR, product_name VARCHAR); CREATE TABLE product_characteristics (product_id VARCHAR, characteristic_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id WHERE t1.product_name = "laurel" [/SQL]


Question: Find the number of characteristics that the product "flax" has.

Answer: [SQL] SELECT COUNT(*) FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id WHERE t1.product_name = "flax" [/SQL]


Question: Find the name of the products that have the color description "red" and have the characteristic name "fast".

Context: CREATE TABLE CHARACTERISTICS (characteristic_id VARCHAR, characteristic_name VARCHAR); CREATE TABLE ref_colors (color_code VARCHAR, color_description VARCHAR); CREATE TABLE products (product_id VARCHAR, color_code VARCHAR); CREATE TABLE product_characteristics (product_id VARCHAR, characteristic_id VARCHAR)

Answer: [SQL] SELECT product_name FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id JOIN ref_colors AS t4 ON t1.color_code = t4.color_code WHERE t4.color_description = "red" AND t3.characteristic_name = "fast" [/SQL]


Question: How many products have the characteristic named "hot"?

Context: CREATE TABLE products (product_id VARCHAR); CREATE TABLE CHARACTERISTICS (characteristic_id VARCHAR, characteristic_name VARCHAR); CREATE TABLE product_characteristics (product_id VARCHAR, characteristic_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id WHERE t3.characteristic_name = "hot" [/SQL]


Question: List the all the distinct names of the products with the characteristic name 'warm'.

Context: CREATE TABLE CHARACTERISTICS (characteristic_id VARCHAR, characteristic_name VARCHAR); CREATE TABLE products (product_name VARCHAR, product_id VARCHAR); CREATE TABLE product_characteristics (product_id VARCHAR, characteristic_id VARCHAR)

Answer: [SQL] SELECT DISTINCT t1.product_name FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id WHERE t3.characteristic_name = "warm" [/SQL]


Question: Find the number of the products that have their color described as "red" and have a characteristic named "slow".

Answer: [SQL] SELECT COUNT(*) FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id JOIN ref_colors AS t4 ON t1.color_code = t4.color_code WHERE t4.color_description = "red" AND t3.characteristic_name = "slow" [/SQL]


Question: Count the products that have the color description "white" or have the characteristic name "hot".

Answer: [SQL] SELECT COUNT(*) FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id JOIN ref_colors AS t4 ON t1.color_code = t4.color_code WHERE t4.color_description = "white" OR t3.characteristic_name = "hot" [/SQL]


Question: What is the unit of measuerment of the product category code "Herbs"?

Context: CREATE TABLE ref_product_categories (unit_of_measure VARCHAR, product_category_code VARCHAR)

Answer: [SQL] SELECT unit_of_measure FROM ref_product_categories WHERE product_category_code = "Herbs" [/SQL]


Question: Find the product category description of the product category with code "Spices".

Context: CREATE TABLE ref_product_categories (product_category_description VARCHAR, product_category_code VARCHAR)

Answer: [SQL] SELECT product_category_description FROM ref_product_categories WHERE product_category_code = "Spices" [/SQL]


Question: What is the product category description and unit of measurement of category "Herbs"?

Context: CREATE TABLE ref_product_categories (product_category_description VARCHAR, unit_of_measure VARCHAR, product_category_code VARCHAR)

Answer: [SQL] SELECT product_category_description, unit_of_measure FROM ref_product_categories WHERE product_category_code = "Herbs" [/SQL]


Question: What is the unit of measurement of product named "cumin"?

Context: CREATE TABLE ref_product_categories (unit_of_measure VARCHAR, product_category_code VARCHAR); CREATE TABLE products (product_category_code VARCHAR, product_name VARCHAR)

Answer: [SQL] SELECT t2.unit_of_measure FROM products AS t1 JOIN ref_product_categories AS t2 ON t1.product_category_code = t2.product_category_code WHERE t1.product_name = "cumin" [/SQL]


Question: Find the unit of measurement and product category code of product named "chervil".

Answer: [SQL] SELECT t2.unit_of_measure, t2.product_category_code FROM products AS t1 JOIN ref_product_categories AS t2 ON t1.product_category_code = t2.product_category_code WHERE t1.product_name = "chervil" [/SQL]


Question: Find the product names that are colored 'white' but do not have unit of measurement "Handful".

Context: CREATE TABLE products (product_name VARCHAR, product_category_code VARCHAR, color_code VARCHAR); CREATE TABLE ref_colors (color_code VARCHAR, color_description VARCHAR); CREATE TABLE ref_product_categories (product_category_code VARCHAR, unit_of_measure VARCHAR)

Answer: [SQL] SELECT t1.product_name FROM products AS t1 JOIN ref_product_categories AS t2 ON t1.product_category_code = t2.product_category_code JOIN ref_colors AS t3 ON t1.color_code = t3.color_code WHERE t3.color_description = "white" AND t2.unit_of_measure <> "Handful" [/SQL]


Question: What is the description of the color for most products?

Context: CREATE TABLE ref_colors (color_description VARCHAR, color_code VARCHAR); CREATE TABLE products (color_code VARCHAR)

Answer: [SQL] SELECT t2.color_description FROM products AS t1 JOIN ref_colors AS t2 ON t1.color_code = t2.color_code GROUP BY t2.color_description ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the description of the color used by least products?

Answer: [SQL] SELECT t2.color_description FROM products AS t1 JOIN ref_colors AS t2 ON t1.color_code = t2.color_code GROUP BY t2.color_description ORDER BY COUNT(*) LIMIT 1 [/SQL]


Question: What is the characteristic name used by most number of the products?

Context: CREATE TABLE products (product_id VARCHAR); CREATE TABLE CHARACTERISTICS (characteristic_name VARCHAR, characteristic_id VARCHAR); CREATE TABLE product_characteristics (product_id VARCHAR, characteristic_id VARCHAR)

Answer: [SQL] SELECT t3.characteristic_name FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id GROUP BY t3.characteristic_name ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What are the names, details and data types of the characteristics which are never used by any product?

Context: CREATE TABLE CHARACTERISTICS (characteristic_name VARCHAR, other_characteristic_details VARCHAR, characteristic_data_type VARCHAR, characteristic_id VARCHAR); CREATE TABLE product_characteristics (characteristic_id VARCHAR); CREATE TABLE CHARACTERISTICS (characteristic_name VARCHAR, other_characteristic_details VARCHAR, characteristic_data_type VARCHAR)

Answer: [SQL] SELECT characteristic_name, other_characteristic_details, characteristic_data_type FROM CHARACTERISTICS EXCEPT SELECT t1.characteristic_name, t1.other_characteristic_details, t1.characteristic_data_type FROM CHARACTERISTICS AS t1 JOIN product_characteristics AS t2 ON t1.characteristic_id = t2.characteristic_id [/SQL]


Question: What are characteristic names used at least twice across all products?

Answer: [SQL] SELECT t3.characteristic_name FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id GROUP BY t3.characteristic_name HAVING COUNT(*) >= 2 [/SQL]


Question: How many colors are never used by any product?

Context: CREATE TABLE products (color_code VARCHAR); CREATE TABLE Ref_colors (color_code VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Ref_colors WHERE NOT color_code IN (SELECT color_code FROM products) [/SQL]


Question: How many events are there?

Context: CREATE TABLE event (Id VARCHAR)

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


Question: List all the event names by year from the most recent to the oldest.

Context: CREATE TABLE event (name VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT name FROM event ORDER BY YEAR DESC [/SQL]


Question: What is the name of the event that happened in the most recent year?

Answer: [SQL] SELECT name FROM event ORDER BY YEAR DESC LIMIT 1 [/SQL]


Question: How many stadiums are there?

Context: CREATE TABLE stadium (Id VARCHAR)

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


Question: Find the name of the stadium that has the maximum capacity.

Context: CREATE TABLE stadium (name VARCHAR, capacity VARCHAR)

Answer: [SQL] SELECT name FROM stadium ORDER BY capacity DESC LIMIT 1 [/SQL]


Question: Find the names of stadiums whose capacity is smaller than the average capacity.

Context: CREATE TABLE stadium (name VARCHAR, capacity INTEGER)

Answer: [SQL] SELECT name FROM stadium WHERE capacity < (SELECT AVG(capacity) FROM stadium) [/SQL]


Question: Find the country that has the most stadiums.

Context: CREATE TABLE stadium (country VARCHAR)

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


Question: Which country has at most 3 stadiums listed?

Context: CREATE TABLE stadium (country VARCHAR)

Answer: [SQL] SELECT country FROM stadium GROUP BY country HAVING COUNT(*) <= 3 [/SQL]


Question: Which country has both stadiums with capacity greater than 60000 and stadiums with capacity less than 50000?

Context: CREATE TABLE stadium (country VARCHAR, capacity INTEGER)

Answer: [SQL] SELECT country FROM stadium WHERE capacity > 60000 INTERSECT SELECT country FROM stadium WHERE capacity < 50000 [/SQL]


Question: How many cities have a stadium that was opened before the year of 2006?

Context: CREATE TABLE stadium (city VARCHAR, opening_year INTEGER)

Answer: [SQL] SELECT COUNT(DISTINCT city) FROM stadium WHERE opening_year < 2006 [/SQL]


Question: How many stadiums does each country have?

Context: CREATE TABLE stadium (country VARCHAR)

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


Question: Which countries do not have a stadium that was opened after 2006?

Context: CREATE TABLE stadium (country VARCHAR, opening_year INTEGER)

Answer: [SQL] SELECT country FROM stadium EXCEPT SELECT country FROM stadium WHERE opening_year > 2006 [/SQL]


Question: How many stadiums are not in country "Russia"?

Context: CREATE TABLE stadium (country VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM stadium WHERE country <> 'Russia' [/SQL]


Question: Find the names of all swimmers, sorted by their 100 meter scores in ascending order.

Context: CREATE TABLE swimmer (name VARCHAR, meter_100 VARCHAR)

Answer: [SQL] SELECT name FROM swimmer ORDER BY meter_100 [/SQL]


Question: How many different countries are all the swimmers from?

Context: CREATE TABLE swimmer (nationality VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT nationality) FROM swimmer [/SQL]


Question: List countries that have more than one swimmer.

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


Question: Find all 200 meter and 300 meter results of swimmers with nationality "Australia".

Context: CREATE TABLE swimmer (meter_200 VARCHAR, meter_300 VARCHAR, nationality VARCHAR)

Answer: [SQL] SELECT meter_200, meter_300 FROM swimmer WHERE nationality = 'Australia' [/SQL]


Question: Find the names of swimmers who has a result of "win".

Context: CREATE TABLE record (swimmer_id VARCHAR); CREATE TABLE swimmer (name VARCHAR, id VARCHAR)

Answer: [SQL] SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id = t2.swimmer_id WHERE RESULT = 'Win' [/SQL]


Question: What is the name of the stadium which held the most events?

Context: CREATE TABLE stadium (name VARCHAR, id VARCHAR); CREATE TABLE event (stadium_id VARCHAR)

Answer: [SQL] SELECT t1.name FROM stadium AS t1 JOIN event AS t2 ON t1.id = t2.stadium_id GROUP BY t2.stadium_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the name and capacity of the stadium where the event named "World Junior" happened.

Context: CREATE TABLE event (stadium_id VARCHAR, name VARCHAR); CREATE TABLE stadium (name VARCHAR, capacity VARCHAR, id VARCHAR)

Answer: [SQL] SELECT t1.name, t1.capacity FROM stadium AS t1 JOIN event AS t2 ON t1.id = t2.stadium_id WHERE t2.name = 'World Junior' [/SQL]


Question: Find the names of stadiums which have never had any event.

Context: CREATE TABLE stadium (name VARCHAR, id VARCHAR, stadium_id VARCHAR); CREATE TABLE event (name VARCHAR, id VARCHAR, stadium_id VARCHAR)

Answer: [SQL] SELECT name FROM stadium WHERE NOT id IN (SELECT stadium_id FROM event) [/SQL]


Question: Find the name of the swimmer who has the most records.

Answer: [SQL] SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id = t2.swimmer_id GROUP BY t2.swimmer_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the name of the swimmer who has at least 2 records.

Answer: [SQL] SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id = t2.swimmer_id GROUP BY t2.swimmer_id HAVING COUNT(*) >= 2 [/SQL]


Question: Find the name and nationality of the swimmer who has won (i.e., has a result of "win") more than 1 time.

Context: CREATE TABLE record (swimmer_id VARCHAR); CREATE TABLE swimmer (name VARCHAR, nationality VARCHAR, id VARCHAR)

Answer: [SQL] SELECT t1.name, t1.nationality FROM swimmer AS t1 JOIN record AS t2 ON t1.id = t2.swimmer_id WHERE RESULT = 'Win' GROUP BY t2.swimmer_id HAVING COUNT(*) > 1 [/SQL]


Question: Find the names of the swimmers who have no record.

Context: CREATE TABLE swimmer (name VARCHAR, id VARCHAR, swimmer_id VARCHAR); CREATE TABLE record (name VARCHAR, id VARCHAR, swimmer_id VARCHAR)

Answer: [SQL] SELECT name FROM swimmer WHERE NOT id IN (SELECT swimmer_id FROM record) [/SQL]


Question: Find the names of the swimmers who have both "win" and "loss" results in the record.

Answer: [SQL] SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id = t2.swimmer_id WHERE RESULT = 'Win' INTERSECT SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id = t2.swimmer_id WHERE RESULT = 'Loss' [/SQL]


Question: Find the names of stadiums that some Australian swimmers have been to.

Context: CREATE TABLE swimmer (id VARCHAR, nationality VARCHAR); CREATE TABLE record (swimmer_id VARCHAR, event_id VARCHAR); CREATE TABLE stadium (name VARCHAR, id VARCHAR); CREATE TABLE event (id VARCHAR, stadium_id VARCHAR)

Answer: [SQL] SELECT t4.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id = t2.swimmer_id JOIN event AS t3 ON t2.event_id = t3.id JOIN stadium AS t4 ON t4.id = t3.stadium_id WHERE t1.nationality = 'Australia' [/SQL]


Question: Find the names of stadiums that the most swimmers have been to.

Context: CREATE TABLE record (event_id VARCHAR); CREATE TABLE stadium (name VARCHAR, id VARCHAR); CREATE TABLE event (stadium_id VARCHAR, id VARCHAR)

Answer: [SQL] SELECT t3.name FROM record AS t1 JOIN event AS t2 ON t1.event_id = t2.id JOIN stadium AS t3 ON t3.id = t2.stadium_id GROUP BY t2.stadium_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find all details for each swimmer.

Context: CREATE TABLE swimmer (Id VARCHAR)

Answer: [SQL] SELECT * FROM swimmer [/SQL]


Question: What is the average capacity of the stadiums that were opened in year 2005?

Context: CREATE TABLE stadium (capacity INTEGER, opening_year VARCHAR)

Answer: [SQL] SELECT AVG(capacity) FROM stadium WHERE opening_year = 2005 [/SQL]


Question: How many railways are there?

Context: CREATE TABLE railway (Id VARCHAR)

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


Question: List the builders of railways in ascending alphabetical order.

Context: CREATE TABLE railway (Builder VARCHAR)

Answer: [SQL] SELECT Builder FROM railway ORDER BY Builder [/SQL]


Question: List the wheels and locations of the railways.

Context: CREATE TABLE railway (Wheels VARCHAR, LOCATION VARCHAR)

Answer: [SQL] SELECT Wheels, LOCATION FROM railway [/SQL]


Question: What is the maximum level of managers in countries that are not "Australia"?

Context: CREATE TABLE manager (LEVEL INTEGER, Country VARCHAR)

Answer: [SQL] SELECT MAX(LEVEL) FROM manager WHERE Country <> "Australia	" [/SQL]


Question: What is the average age for all managers?

Context: CREATE TABLE manager (Age INTEGER)

Answer: [SQL] SELECT AVG(Age) FROM manager [/SQL]


Question: What are the names of managers in ascending order of level?

Context: CREATE TABLE manager (Name VARCHAR, LEVEL VARCHAR)

Answer: [SQL] SELECT Name FROM manager ORDER BY LEVEL [/SQL]


Question: What are the names and arrival times of trains?

Context: CREATE TABLE train (Name VARCHAR, Arrival VARCHAR)

Answer: [SQL] SELECT Name, Arrival FROM train [/SQL]


Question: What is the name of the oldest manager?

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

Answer: [SQL] SELECT Name FROM manager ORDER BY Age DESC LIMIT 1 [/SQL]


Question: Show the names of trains and locations of railways they are in.

Context: CREATE TABLE railway (Location VARCHAR, Railway_ID VARCHAR); CREATE TABLE train (Name VARCHAR, Railway_ID VARCHAR)

Answer: [SQL] SELECT T2.Name, T1.Location FROM railway AS T1 JOIN train AS T2 ON T1.Railway_ID = T2.Railway_ID [/SQL]


Question: Show the builder of railways associated with the trains named "Andaman Exp".

Context: CREATE TABLE railway (Builder VARCHAR, Railway_ID VARCHAR); CREATE TABLE train (Railway_ID VARCHAR, Name VARCHAR)

Answer: [SQL] SELECT T1.Builder FROM railway AS T1 JOIN train AS T2 ON T1.Railway_ID = T2.Railway_ID WHERE T2.Name = "Andaman Exp" [/SQL]


Question: Show id and location of railways that are associated with more than one train.

Context: CREATE TABLE railway (Location VARCHAR, Railway_ID VARCHAR); CREATE TABLE train (Railway_ID VARCHAR)

Answer: [SQL] SELECT T2.Railway_ID, T1.Location FROM railway AS T1 JOIN train AS T2 ON T1.Railway_ID = T2.Railway_ID GROUP BY T2.Railway_ID HAVING COUNT(*) > 1 [/SQL]


Question: Show the id and builder of the railway that are associated with the most trains.

Context: CREATE TABLE train (Railway_ID VARCHAR); CREATE TABLE railway (Builder VARCHAR, Railway_ID VARCHAR)

Answer: [SQL] SELECT T2.Railway_ID, T1.Builder FROM railway AS T1 JOIN train AS T2 ON T1.Railway_ID = T2.Railway_ID GROUP BY T2.Railway_ID ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show different builders of railways, along with the corresponding number of railways using each builder.

Context: CREATE TABLE railway (Builder VARCHAR)

Answer: [SQL] SELECT Builder, COUNT(*) FROM railway GROUP BY Builder [/SQL]


Question: Show the most common builder of railways.

Context: CREATE TABLE railway (Builder VARCHAR)

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


Question: Show different locations of railways along with the corresponding number of railways at each location.

Context: CREATE TABLE railway (LOCATION VARCHAR)

Answer: [SQL] SELECT LOCATION, COUNT(*) FROM railway GROUP BY LOCATION [/SQL]


Question: Show the locations that have more than one railways.

Context: CREATE TABLE railway (LOCATION VARCHAR)

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


Question: List the object number of railways that do not have any trains.

Context: CREATE TABLE train (ObjectNumber VARCHAR, Railway_ID VARCHAR); CREATE TABLE railway (ObjectNumber VARCHAR, Railway_ID VARCHAR)

Answer: [SQL] SELECT ObjectNumber FROM railway WHERE NOT Railway_ID IN (SELECT Railway_ID FROM train) [/SQL]


Question: Show the countries that have both managers of age above 50 and managers of age below 46.

Context: CREATE TABLE manager (Country VARCHAR, Age INTEGER)

Answer: [SQL] SELECT Country FROM manager WHERE Age > 50 INTERSECT SELECT Country FROM manager WHERE Age < 46 [/SQL]


Question: Show the distinct countries of managers.

Context: CREATE TABLE manager (Country VARCHAR)

Answer: [SQL] SELECT DISTINCT Country FROM manager [/SQL]


Question: Show the working years of managers in descending order of their level.

Context: CREATE TABLE manager (Working_year_starts VARCHAR, LEVEL VARCHAR)

Answer: [SQL] SELECT Working_year_starts FROM manager ORDER BY LEVEL DESC [/SQL]


Question: Show the countries that have managers of age above 50 or below 46.

Context: CREATE TABLE manager (Country VARCHAR, Age VARCHAR)

Answer: [SQL] SELECT Country FROM manager WHERE Age > 50 OR Age < 46 [/SQL]


Question: How many addresses are there in country USA?

Context: CREATE TABLE addresses (country VARCHAR)

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


Question: Show all distinct cities in the address record.

Context: CREATE TABLE addresses (city VARCHAR)

Answer: [SQL] SELECT DISTINCT city FROM addresses [/SQL]


Question: Show each state and the number of addresses in each state.

Context: CREATE TABLE addresses (state_province_county VARCHAR)

Answer: [SQL] SELECT state_province_county, COUNT(*) FROM addresses GROUP BY state_province_county [/SQL]


Question: Show names and phones of customers who do not have address information.

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

Answer: [SQL] SELECT customer_name, customer_phone FROM customers WHERE NOT customer_id IN (SELECT customer_id FROM customer_address_history) [/SQL]


Question: Show the name of the customer who has the most orders.

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

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


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

Context: CREATE TABLE products (product_type_code VARCHAR)

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


Question: Show the names of customers who have both an order in completed status and an order in part status.

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

Answer: [SQL] SELECT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = 'Completed' INTERSECT SELECT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = 'Part' [/SQL]


Question: Show the name, phone, and payment method code for all customers in descending order of customer number.

Context: CREATE TABLE customers (customer_name VARCHAR, customer_phone VARCHAR, payment_method_code VARCHAR, customer_number VARCHAR)

Answer: [SQL] SELECT customer_name, customer_phone, payment_method_code FROM customers ORDER BY customer_number DESC [/SQL]


Question: Show the product name and total order quantity for each product.

Context: CREATE TABLE products (product_name VARCHAR, product_id VARCHAR); CREATE TABLE order_items (order_quantity INTEGER, product_id VARCHAR)

Answer: [SQL] SELECT T1.product_name, SUM(T2.order_quantity) FROM products AS T1 JOIN order_items AS T2 ON T1.product_id = T2.product_id GROUP BY T1.product_id [/SQL]


Question: Show the minimum, maximum, average price for all products.

Context: CREATE TABLE products (product_price INTEGER)

Answer: [SQL] SELECT MIN(product_price), MAX(product_price), AVG(product_price) FROM products [/SQL]


Question: How many products have a price higher than the average?

Answer: [SQL] SELECT COUNT(*) FROM products WHERE product_price > (SELECT AVG(product_price) FROM products) [/SQL]


Question: Show the customer name, customer address city, date from, and date to for each customer address history.

Context: CREATE TABLE addresses (city VARCHAR, address_id VARCHAR); CREATE TABLE customers (customer_name VARCHAR, customer_id VARCHAR); CREATE TABLE customer_address_history (date_from VARCHAR, date_to VARCHAR, customer_id VARCHAR, address_id VARCHAR)

Answer: [SQL] SELECT T2.customer_name, T3.city, T1.date_from, T1.date_to FROM customer_address_history AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id JOIN addresses AS T3 ON T1.address_id = T3.address_id [/SQL]


Question: Show the names of customers who use Credit Card payment method and have more than 2 orders.

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

Answer: [SQL] SELECT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T1.payment_method_code = 'Credit Card' GROUP BY T1.customer_id HAVING COUNT(*) > 2 [/SQL]


Question: What are the name and phone of the customer with the most ordered product quantity?

Context: CREATE TABLE order_items (order_id VARCHAR, order_quantity INTEGER); CREATE TABLE customers (customer_name VARCHAR, customer_phone VARCHAR, customer_id VARCHAR); CREATE TABLE customer_orders (customer_id VARCHAR, order_id VARCHAR)

Answer: [SQL] SELECT T1.customer_name, T1.customer_phone FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id JOIN order_items AS T3 ON T3.order_id = T2.order_id GROUP BY T1.customer_id ORDER BY SUM(T3.order_quantity) DESC LIMIT 1 [/SQL]


Question: Show the product type and name for the products with price higher than 1000 or lower than 500.

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

Answer: [SQL] SELECT product_type_code, product_name FROM products WHERE product_price > 1000 OR product_price < 500 [/SQL]


Question: Find the name of dorms only for female (F gender).

Context: CREATE TABLE dorm (dorm_name VARCHAR, gender VARCHAR)

Answer: [SQL] SELECT dorm_name FROM dorm WHERE gender = 'F' [/SQL]


Question: Find the name of dorms that can accommodate more than 300 students.

Context: CREATE TABLE dorm (dorm_name VARCHAR, student_capacity INTEGER)

Answer: [SQL] SELECT dorm_name FROM dorm WHERE student_capacity > 300 [/SQL]


Question: How many female students (sex is F) whose age is below 25?

Context: CREATE TABLE student (sex VARCHAR, age VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM student WHERE sex = 'F' AND age < 25 [/SQL]


Question: Find the first name of students who is older than 20.

Context: CREATE TABLE student (fname VARCHAR, age INTEGER)

Answer: [SQL] SELECT fname FROM student WHERE age > 20 [/SQL]


Question: Find the first name of students living in city PHL whose age is between 20 and 25.

Context: CREATE TABLE student (fname VARCHAR, city_code VARCHAR, age VARCHAR)

Answer: [SQL] SELECT fname FROM student WHERE city_code = 'PHL' AND age BETWEEN 20 AND 25 [/SQL]


Question: How many dorms are there?

Context: CREATE TABLE dorm (Id VARCHAR)

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


Question: Find the number of distinct amenities.

Context: CREATE TABLE dorm_amenity (Id VARCHAR)

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


Question: Find the total capacity of all dorms.

Context: CREATE TABLE dorm (student_capacity INTEGER)

Answer: [SQL] SELECT SUM(student_capacity) FROM dorm [/SQL]


Question: Find the average age of all students living in the each city.

Context: CREATE TABLE student (city_code VARCHAR, age INTEGER)

Answer: [SQL] SELECT AVG(age), city_code FROM student GROUP BY city_code [/SQL]


Question: Find the average and total capacity of dorms for the students with gender X.

Context: CREATE TABLE dorm (student_capacity INTEGER, gender VARCHAR)

Answer: [SQL] SELECT AVG(student_capacity), SUM(student_capacity) FROM dorm WHERE gender = 'X' [/SQL]


Question: Find the number of dorms that have some amenity.

Context: CREATE TABLE has_amenity (dormid VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT dormid) FROM has_amenity [/SQL]


Question: Find the name of dorms that do not have any amenity

Context: CREATE TABLE dorm (dorm_name VARCHAR, dormid VARCHAR); CREATE TABLE has_amenity (dorm_name VARCHAR, dormid VARCHAR)

Answer: [SQL] SELECT dorm_name FROM dorm WHERE NOT dormid IN (SELECT dormid FROM has_amenity) [/SQL]


Question: Find the number of distinct gender for dorms.

Context: CREATE TABLE dorm (gender VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT gender) FROM dorm [/SQL]


Question: Find the capacity and gender type of the dorm whose name has substring ‘Donor’.

Context: CREATE TABLE dorm (student_capacity VARCHAR, gender VARCHAR, dorm_name VARCHAR)

Answer: [SQL] SELECT student_capacity, gender FROM dorm WHERE dorm_name LIKE '%Donor%' [/SQL]


Question: Find the name and gender type of the dorms whose capacity is greater than 300 or less than 100.

Context: CREATE TABLE dorm (dorm_name VARCHAR, gender VARCHAR, student_capacity VARCHAR)

Answer: [SQL] SELECT dorm_name, gender FROM dorm WHERE student_capacity > 300 OR student_capacity < 100 [/SQL]


Question: Find the numbers of different majors and cities.

Context: CREATE TABLE student (major VARCHAR, city_code VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT major), COUNT(DISTINCT city_code) FROM student [/SQL]


Question: Find the name of dorms which have both TV Lounge and Study Room as amenities.

Context: CREATE TABLE dorm (dorm_name VARCHAR, dormid VARCHAR); CREATE TABLE has_amenity (dormid VARCHAR, amenid VARCHAR); CREATE TABLE dorm_amenity (amenid VARCHAR, amenity_name VARCHAR)

Answer: [SQL] SELECT T1.dorm_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T3.amenity_name = 'TV Lounge' INTERSECT SELECT T1.dorm_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T3.amenity_name = 'Study Room' [/SQL]


Question: Find the name of dorms which have TV Lounge but no Study Room as amenity.

Answer: [SQL] SELECT T1.dorm_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T3.amenity_name = 'TV Lounge' EXCEPT SELECT T1.dorm_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T3.amenity_name = 'Study Room' [/SQL]


Question: Find the last name of students who is either female (sex is F) and living in the city of code BAL or male (sex is M) and in age of below 20.

Context: CREATE TABLE student (lname VARCHAR, sex VARCHAR, city_code VARCHAR, age VARCHAR)

Answer: [SQL] SELECT lname FROM student WHERE sex = 'F' AND city_code = 'BAL' UNION SELECT lname FROM student WHERE sex = 'M' AND age < 20 [/SQL]


Question: Find the name of the dorm with the largest capacity.

Context: CREATE TABLE dorm (dorm_name VARCHAR, student_capacity VARCHAR)

Answer: [SQL] SELECT dorm_name FROM dorm ORDER BY student_capacity DESC LIMIT 1 [/SQL]


Question: List in alphabetic order all different amenities.

Context: CREATE TABLE dorm_amenity (amenity_name VARCHAR)

Answer: [SQL] SELECT amenity_name FROM dorm_amenity ORDER BY amenity_name [/SQL]


Question: Find the code of city where most of students are living in.

Context: CREATE TABLE student (city_code VARCHAR)

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


Question: Find the first and last name of students whose age is younger than the average age.

Context: CREATE TABLE student (fname VARCHAR, lname VARCHAR, age INTEGER)

Answer: [SQL] SELECT fname, lname FROM student WHERE age < (SELECT AVG(age) FROM student) [/SQL]


Question: List the first and last name of students who are not living in the city with code HKG, and sorted the results by their ages.

Context: CREATE TABLE student (fname VARCHAR, lname VARCHAR, city_code VARCHAR, age VARCHAR)

Answer: [SQL] SELECT fname, lname FROM student WHERE city_code <> 'HKG' ORDER BY age [/SQL]


Question: List name of all amenities which Anonymous Donor Hall has, and sort the results in alphabetic order.

Context: CREATE TABLE has_amenity (amenid VARCHAR, dormid VARCHAR); CREATE TABLE dorm_amenity (amenity_name VARCHAR, amenid VARCHAR); CREATE TABLE dorm (dormid VARCHAR, dorm_name VARCHAR)

Answer: [SQL] SELECT T1.amenity_name FROM dorm_amenity AS T1 JOIN has_amenity AS T2 ON T2.amenid = T1.amenid JOIN dorm AS T3 ON T2.dormid = T3.dormid WHERE T3.dorm_name = 'Anonymous Donor Hall' ORDER BY T1.amenity_name [/SQL]


Question: Find the number of dorms and total capacity for each gender.

Context: CREATE TABLE dorm (gender VARCHAR, student_capacity INTEGER)

Answer: [SQL] SELECT COUNT(*), SUM(student_capacity), gender FROM dorm GROUP BY gender [/SQL]


Question: Find the average and oldest age for students with different sex.

Context: CREATE TABLE student (sex VARCHAR, age INTEGER)

Answer: [SQL] SELECT AVG(age), MAX(age), sex FROM student GROUP BY sex [/SQL]


Question: Find the number of students in each major.

Context: CREATE TABLE student (major VARCHAR)

Answer: [SQL] SELECT COUNT(*), major FROM student GROUP BY major [/SQL]


Question: Find the number and average age of students living in each city.

Context: CREATE TABLE student (city_code VARCHAR, age INTEGER)

Answer: [SQL] SELECT COUNT(*), AVG(age), city_code FROM student GROUP BY city_code [/SQL]


Question: Find the average age and number of male students (with sex M) from each city.

Context: CREATE TABLE student (city_code VARCHAR, age INTEGER, sex VARCHAR)

Answer: [SQL] SELECT COUNT(*), AVG(age), city_code FROM student WHERE sex = 'M' GROUP BY city_code [/SQL]


Question: Find the number of students for the cities where have more than one student.

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


Question: Find the first and last name of students who are not in the largest major.

Context: CREATE TABLE student (fname VARCHAR, lname VARCHAR, major VARCHAR)

Answer: [SQL] SELECT fname, lname FROM student WHERE major <> (SELECT major FROM student GROUP BY major ORDER BY COUNT(*) DESC LIMIT 1) [/SQL]


Question: Find the number of students whose age is older than the average age for each gender.

Answer: [SQL] SELECT COUNT(*), sex FROM student WHERE age > (SELECT AVG(age) FROM student) GROUP BY sex [/SQL]


Question: Find the average age of students living in each dorm and the name of dorm.

Context: CREATE TABLE dorm (dorm_name VARCHAR, dormid VARCHAR); CREATE TABLE student (age INTEGER, stuid VARCHAR); CREATE TABLE lives_in (stuid VARCHAR, dormid VARCHAR)

Answer: [SQL] SELECT AVG(T1.age), T3.dorm_name FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid GROUP BY T3.dorm_name [/SQL]