Question: Find the names of all reviewers who have contributed three or more ratings.

Context: CREATE TABLE Reviewer (name VARCHAR, rID VARCHAR); CREATE TABLE Rating (rID VARCHAR)

SELECT T2.name FROM Rating AS T1 JOIN Reviewer AS T2 ON T1.rID = T2.rID GROUP BY T1.rID HAVING COUNT(*) >= 3


Question: Find the names of all reviewers who rated Gone with the Wind.

Context: CREATE TABLE Movie (mID VARCHAR, title VARCHAR); CREATE TABLE Reviewer (name VARCHAR, rID VARCHAR); CREATE TABLE Rating (mID VARCHAR, rID VARCHAR)

SELECT DISTINCT T3.name FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID JOIN Reviewer AS T3 ON T1.rID = T3.rID WHERE T2.title = 'Gone with the Wind'


Question: Find the names of all directors whose movies are rated by Sarah Martinez.

Context: CREATE TABLE Reviewer (rID VARCHAR, name VARCHAR); CREATE TABLE Movie (director VARCHAR, mID VARCHAR); CREATE TABLE Rating (mID VARCHAR, rID VARCHAR)

SELECT DISTINCT T2.director FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID JOIN Reviewer AS T3 ON T1.rID = T3.rID WHERE T3.name = 'Sarah Martinez'


Question: For any rating where the name of reviewer is the same as the director of the movie, return the reviewer name, movie title, and number of stars.

Context: CREATE TABLE Rating (stars VARCHAR, mID VARCHAR, rID VARCHAR); CREATE TABLE Reviewer (name VARCHAR, rID VARCHAR); CREATE TABLE Movie (title VARCHAR, mID VARCHAR, director VARCHAR)

SELECT DISTINCT T3.name, T2.title, T1.stars FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID JOIN Reviewer AS T3 ON T1.rID = T3.rID WHERE T2.director = T3.name


Question: Return all reviewer names and movie names together in a single list.

Context: CREATE TABLE Reviewer (name VARCHAR, title VARCHAR); CREATE TABLE Movie (name VARCHAR, title VARCHAR)

SELECT name FROM Reviewer UNION SELECT title FROM Movie


Question: Find the titles of all movies not reviewed by Chris Jackson.

Context: CREATE TABLE Reviewer (rID VARCHAR, name VARCHAR); CREATE TABLE Movie (title VARCHAR, mID VARCHAR); CREATE TABLE Movie (title VARCHAR); CREATE TABLE Rating (mID VARCHAR, rID VARCHAR)

SELECT DISTINCT title FROM Movie EXCEPT SELECT T2.title FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID JOIN Reviewer AS T3 ON T1.rID = T3.rID WHERE T3.name = 'Chris Jackson'


Question: For all directors who directed more than one movie, return the titles of all movies directed by them, along with the director name. Sort by director name, then movie title.

Context: CREATE TABLE Movie (title VARCHAR, director VARCHAR); CREATE TABLE Movie (director VARCHAR, title VARCHAR)

SELECT T1.title, T1.director FROM Movie AS T1 JOIN Movie AS T2 ON T1.director = T2.director WHERE T1.title <> T2.title ORDER BY T1.director, T1.title


Question: For directors who had more than one movie, return the titles and produced years of all movies directed by them.

Context: CREATE TABLE Movie (director VARCHAR, title VARCHAR); CREATE TABLE Movie (title VARCHAR, year VARCHAR, director VARCHAR)

SELECT T1.title, T1.year FROM Movie AS T1 JOIN Movie AS T2 ON T1.director = T2.director WHERE T1.title <> T2.title


Question: What are the names of the directors who made exactly one movie?

Context: CREATE TABLE Movie (director VARCHAR)

SELECT director FROM Movie GROUP BY director HAVING COUNT(*) = 1


Question: What are the names of the directors who made exactly one movie excluding director NULL?

Context: CREATE TABLE Movie (director VARCHAR)

SELECT director FROM Movie WHERE director <> "null" GROUP BY director HAVING COUNT(*) = 1


Question: How many movie reviews does each director get?

Context: CREATE TABLE Rating (mID VARCHAR); CREATE TABLE Movie (director VARCHAR, mID VARCHAR)

SELECT COUNT(*), T1.director FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director


Question: Find the movies with the highest average rating. Return the movie titles and average rating.

Context: CREATE TABLE Rating (stars INTEGER, mID VARCHAR); CREATE TABLE Movie (title VARCHAR, mID VARCHAR)

SELECT T2.title, AVG(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID GROUP BY T1.mID ORDER BY AVG(T1.stars) DESC LIMIT 1


Question: What are the movie titles and average rating of the movies with the lowest average rating?

SELECT T2.title, AVG(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID GROUP BY T1.mID ORDER BY AVG(T1.stars) LIMIT 1


Question: What are the names and years of the movies that has the top 3 highest rating star?

Context: CREATE TABLE Rating (mID VARCHAR, stars VARCHAR); CREATE TABLE Movie (title VARCHAR, year VARCHAR, mID VARCHAR)

SELECT T2.title, T2.year FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID ORDER BY T1.stars DESC LIMIT 3


Question: For each director, return the director's name together with the title of the movie they directed that received the highest rating among all of their movies, and the value of that rating. Ignore movies whose director is NULL.

Context: CREATE TABLE Rating (stars INTEGER, mID VARCHAR); CREATE TABLE Movie (title VARCHAR, director VARCHAR, mID VARCHAR)

SELECT T2.title, T1.stars, T2.director, MAX(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID WHERE director <> "null" GROUP BY director


Question: Find the title and star rating of the movie that got the least rating star for each reviewer.

Context: CREATE TABLE Rating (rID VARCHAR, stars INTEGER, mID VARCHAR); CREATE TABLE Movie (title VARCHAR, mID VARCHAR)

SELECT T2.title, T1.rID, T1.stars, MIN(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID GROUP BY T1.rID


Question: Find the title and score of the movie with the lowest rating among all movies directed by each director.

SELECT T2.title, T1.stars, T2.director, MIN(T1.stars) FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID GROUP BY T2.director


Question: What is the name of the movie that is rated by most of times?

Context: CREATE TABLE Rating (mID VARCHAR); CREATE TABLE Movie (title VARCHAR, mID VARCHAR)

SELECT T2.title, T1.mID FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID GROUP BY T1.mID ORDER BY COUNT(*) DESC LIMIT 1


Question: What are the titles of all movies that have rating star is between 3 and 5?

Context: CREATE TABLE Rating (mID VARCHAR, stars INTEGER); CREATE TABLE Movie (title VARCHAR, mID VARCHAR)

SELECT T2.title FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID WHERE T1.stars BETWEEN 3 AND 5


Question: Find the names of reviewers who had given higher than 3 star ratings.

Context: CREATE TABLE Reviewer (name VARCHAR, rID VARCHAR); CREATE TABLE Rating (rID VARCHAR, stars INTEGER)

SELECT T2.name FROM Rating AS T1 JOIN Reviewer AS T2 ON T1.rID = T2.rID WHERE T1.stars > 3


Question: Find the average rating star for each movie that are not reviewed by Brittany Harris.

Context: CREATE TABLE Reviewer (rID VARCHAR, name VARCHAR); CREATE TABLE Rating (mID VARCHAR, stars INTEGER); CREATE TABLE Rating (mID VARCHAR, rID VARCHAR)

SELECT mID, AVG(stars) FROM Rating WHERE NOT mID IN (SELECT T1.mID FROM Rating AS T1 JOIN Reviewer AS T2 ON T1.rID = T2.rID WHERE T2.name = "Brittany Harris") GROUP BY mID


Question: What are the ids of the movies that are not reviewed by Brittany Harris.

Context: CREATE TABLE Reviewer (rID VARCHAR, name VARCHAR); CREATE TABLE Rating (mID VARCHAR); CREATE TABLE Rating (mID VARCHAR, rID VARCHAR)

SELECT mID FROM Rating EXCEPT SELECT T1.mID FROM Rating AS T1 JOIN Reviewer AS T2 ON T1.rID = T2.rID WHERE T2.name = "Brittany Harris"


Question: Find the average rating star for each movie that received at least 2 ratings.

Context: CREATE TABLE Rating (mID VARCHAR, stars INTEGER)

SELECT mID, AVG(stars) FROM Rating GROUP BY mID HAVING COUNT(*) >= 2


Question: find the ids of reviewers who did not give 4 star.

Context: CREATE TABLE Rating (rID VARCHAR, stars VARCHAR)

SELECT rID FROM Rating EXCEPT SELECT rID FROM Rating WHERE stars = 4


Question: Find the ids of reviewers who didn't only give 4 star.


Question: What are names of the movies that are either made after 2000 or reviewed by Brittany Harris?

Context: CREATE TABLE Reviewer (rID VARCHAR, name VARCHAR); CREATE TABLE Movie (title VARCHAR, mID VARCHAR, year VARCHAR); CREATE TABLE Rating (mID VARCHAR, rID VARCHAR)

SELECT DISTINCT T2.title FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID JOIN Reviewer AS T3 ON T1.rID = T3.rID WHERE T3.name = 'Brittany Harris' OR T2.year > 2000


Question: What are names of the movies that are either made before 1980 or directed by James Cameron?

Context: CREATE TABLE Movie (title VARCHAR, director VARCHAR, YEAR VARCHAR)

SELECT title FROM Movie WHERE director = "James Cameron" OR YEAR < 1980


Question: What are the names of reviewers who had rated 3 star and 4 star?

Context: CREATE TABLE Reviewer (name VARCHAR, rID VARCHAR); CREATE TABLE Rating (rID VARCHAR, stars VARCHAR)

SELECT T2.name FROM Rating AS T1 JOIN Reviewer AS T2 ON T1.rID = T2.rID WHERE T1.stars = 3 INTERSECT SELECT T2.name FROM Rating AS T1 JOIN Reviewer AS T2 ON T1.rID = T2.rID WHERE T1.stars = 4


Question: What are the names of movies that get 3 star and 4 star?

Context: CREATE TABLE Rating (mID VARCHAR, stars VARCHAR); CREATE TABLE Movie (title VARCHAR, mID VARCHAR)

SELECT T2.title FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID WHERE T1.stars = 3 INTERSECT SELECT T2.title FROM Rating AS T1 JOIN Movie AS T2 ON T1.mID = T2.mID WHERE T1.stars = 4


Question: How many counties are there?

Context: CREATE TABLE county_public_safety (Id VARCHAR)

SELECT COUNT(*) FROM county_public_safety


Question: List the names of counties in descending order of population.

Context: CREATE TABLE county_public_safety (Name VARCHAR, Population VARCHAR)

SELECT Name FROM county_public_safety ORDER BY Population DESC


Question: List the distinct police forces of counties whose location is not on east side.

Context: CREATE TABLE county_public_safety (Police_force VARCHAR, LOCATION VARCHAR)

SELECT DISTINCT Police_force FROM county_public_safety WHERE LOCATION <> "East"


Question: What are the minimum and maximum crime rate of counties?

Context: CREATE TABLE county_public_safety (Crime_rate INTEGER)

SELECT MIN(Crime_rate), MAX(Crime_rate) FROM county_public_safety


Question: Show the crime rates of counties in ascending order of number of police officers.

Context: CREATE TABLE county_public_safety (Crime_rate VARCHAR, Police_officers VARCHAR)

SELECT Crime_rate FROM county_public_safety ORDER BY Police_officers


Question: What are the names of cities in ascending alphabetical order?

Context: CREATE TABLE city (Name VARCHAR)


Question: What are the percentage of hispanics in cities with the black percentage higher than 10?

Context: CREATE TABLE city (Hispanic VARCHAR, Black INTEGER)

SELECT Hispanic FROM city WHERE Black > 10


Question: List the name of the county with the largest population.

SELECT Name FROM county_public_safety ORDER BY Population DESC LIMIT 1


Question: List the names of the city with the top 5 white percentages.

Context: CREATE TABLE city (Name VARCHAR, White VARCHAR)

SELECT Name FROM city ORDER BY White DESC LIMIT 5


Question: Show names of cities and names of counties they are in.

Context: CREATE TABLE city (Name VARCHAR, County_ID VARCHAR); CREATE TABLE county_public_safety (Name VARCHAR, County_ID VARCHAR)

SELECT T1.Name, T2.Name FROM city AS T1 JOIN county_public_safety AS T2 ON T1.County_ID = T2.County_ID


Question: Show white percentages of cities and the crime rates of counties they are in.

Context: CREATE TABLE city (White VARCHAR, County_ID VARCHAR); CREATE TABLE county_public_safety (Crime_rate VARCHAR, County_ID VARCHAR)

SELECT T1.White, T2.Crime_rate FROM city AS T1 JOIN county_public_safety AS T2 ON T1.County_ID = T2.County_ID


Question: Show the name of cities in the county that has the largest number of police officers.

Context: CREATE TABLE city (name VARCHAR, county_ID VARCHAR, Police_officers VARCHAR); CREATE TABLE county_public_safety (name VARCHAR, county_ID VARCHAR, Police_officers VARCHAR)

SELECT name FROM city WHERE county_ID = (SELECT county_ID FROM county_public_safety ORDER BY Police_officers DESC LIMIT 1)


Question: Show the number of cities in counties that have a population more than 20000.

Context: CREATE TABLE county_public_safety (county_ID VARCHAR, population INTEGER); CREATE TABLE city (county_ID VARCHAR, population INTEGER)

SELECT COUNT(*) FROM city WHERE county_ID IN (SELECT county_ID FROM county_public_safety WHERE population > 20000)


Question: Show the crime rate of counties with a city having white percentage more than 90.

Context: CREATE TABLE county_public_safety (Crime_rate VARCHAR, County_ID VARCHAR); CREATE TABLE city (County_ID VARCHAR, White INTEGER)

SELECT T2.Crime_rate FROM city AS T1 JOIN county_public_safety AS T2 ON T1.County_ID = T2.County_ID WHERE T1.White > 90


Question: Please show the police forces and the number of counties with each police force.

Context: CREATE TABLE county_public_safety (Police_force VARCHAR)

SELECT Police_force, COUNT(*) FROM county_public_safety GROUP BY Police_force


Question: What is the location shared by most counties?

Context: CREATE TABLE county_public_safety (LOCATION VARCHAR)

SELECT LOCATION FROM county_public_safety GROUP BY LOCATION ORDER BY COUNT(*) DESC LIMIT 1


Question: List the names of counties that do not have any cities.

SELECT Name FROM county_public_safety WHERE NOT County_ID IN (SELECT County_ID FROM city)


Question: Show the police force shared by counties with location on the east and west.

SELECT Police_force FROM county_public_safety WHERE LOCATION = "East" INTERSECT SELECT Police_force FROM county_public_safety WHERE LOCATION = "West"


Question: Show the names of cities in counties that have a crime rate less than 100.

Context: CREATE TABLE county_public_safety (name VARCHAR, county_id VARCHAR, Crime_rate INTEGER); CREATE TABLE city (name VARCHAR, county_id VARCHAR, Crime_rate INTEGER)

SELECT name FROM city WHERE county_id IN (SELECT county_id FROM county_public_safety WHERE Crime_rate < 100)


Question: Show the case burden of counties in descending order of population.

Context: CREATE TABLE county_public_safety (Case_burden VARCHAR, Population VARCHAR)

SELECT Case_burden FROM county_public_safety ORDER BY Population DESC


Question: Find the names of all modern rooms with a base price below $160 and two beds.

Context: CREATE TABLE Rooms (roomName VARCHAR, decor VARCHAR, basePrice VARCHAR, beds VARCHAR)

SELECT roomName FROM Rooms WHERE basePrice < 160 AND beds = 2 AND decor = 'modern'


Question: Find all the rooms that have a price higher than 160 and can accommodate more than 2 people. Report room names and ids.

Context: CREATE TABLE Rooms (roomName VARCHAR, RoomId VARCHAR, basePrice VARCHAR, maxOccupancy VARCHAR)

SELECT roomName, RoomId FROM Rooms WHERE basePrice > 160 AND maxOccupancy > 2


Question: Find the most popular room in the hotel. The most popular room is the room that had seen the largest number of reservations.

Context: CREATE TABLE Reservations (Room VARCHAR); CREATE TABLE Rooms (roomName VARCHAR, RoomId VARCHAR)

SELECT T2.roomName FROM Reservations AS T1 JOIN Rooms AS T2 ON T1.Room = T2.RoomId GROUP BY T1.Room ORDER BY COUNT(*) DESC LIMIT 1


Question: How many kids stay in the rooms reserved by ROY SWEAZY?

Context: CREATE TABLE Reservations (kids VARCHAR, FirstName VARCHAR, LastName VARCHAR)

SELECT kids FROM Reservations WHERE FirstName = "ROY" AND LastName = "SWEAZY"


Question: How many times does ROY SWEAZY has reserved a room.

Context: CREATE TABLE Reservations (FirstName VARCHAR, LastName VARCHAR)

SELECT COUNT(*) FROM Reservations WHERE FirstName = "ROY" AND LastName = "SWEAZY"


Question: Which room has the highest rate? List the room's full name, rate, check in and check out date.

Context: CREATE TABLE Rooms (roomName VARCHAR, RoomId VARCHAR); CREATE TABLE Reservations (Rate VARCHAR, CheckIn VARCHAR, CheckOut VARCHAR, Room VARCHAR)

SELECT T2.roomName, T1.Rate, T1.CheckIn, T1.CheckOut FROM Reservations AS T1 JOIN Rooms AS T2 ON T1.Room = T2.RoomId GROUP BY T1.Room ORDER BY T1.Rate DESC LIMIT 1


Question: How many adults stay in the room CONRAD SELBIG checked in on Oct 23, 2010?

Context: CREATE TABLE Reservations (Adults VARCHAR, LastName VARCHAR, CheckIn VARCHAR, FirstName VARCHAR)

SELECT Adults FROM Reservations WHERE CheckIn = "2010-10-23" AND FirstName = "CONRAD" AND LastName = "SELBIG"


Question: How many kids stay in the room DAMIEN TRACHSEL checked in on Sep 21, 2010?

Context: CREATE TABLE Reservations (Kids VARCHAR, LastName VARCHAR, CheckIn VARCHAR, FirstName VARCHAR)

SELECT Kids FROM Reservations WHERE CheckIn = "2010-09-21" AND FirstName = "DAMIEN" AND LastName = "TRACHSEL"


Question: How many king beds are there?

Context: CREATE TABLE Rooms (beds INTEGER, bedtype VARCHAR)

SELECT SUM(beds) FROM Rooms WHERE bedtype = 'King'


Question: List the names and decor of rooms that have a king bed. Sort the list by their price.

Context: CREATE TABLE Rooms (roomName VARCHAR, decor VARCHAR, bedtype VARCHAR, basePrice VARCHAR)

SELECT roomName, decor FROM Rooms WHERE bedtype = 'King' ORDER BY basePrice


Question: Which room has cheapest base price? List the room's name and the base price.

Context: CREATE TABLE Rooms (roomName VARCHAR, basePrice VARCHAR)

SELECT roomName, basePrice FROM Rooms ORDER BY basePrice LIMIT 1


Question: What is the decor of room Recluse and defiance?

Context: CREATE TABLE Rooms (decor VARCHAR, roomName VARCHAR)

SELECT decor FROM Rooms WHERE roomName = "Recluse and defiance"


Question: What is the average base price of different bed type? List bed type and average base price.

Context: CREATE TABLE Rooms (bedType VARCHAR, basePrice INTEGER)

SELECT bedType, AVG(basePrice) FROM Rooms GROUP BY bedType


Question: What is the total number of people who could stay in the modern rooms in this inn?

Context: CREATE TABLE Rooms (maxOccupancy INTEGER, decor VARCHAR)

SELECT SUM(maxOccupancy) FROM Rooms WHERE decor = 'modern'


Question: What kind of decor has the least number of reservations?

Context: CREATE TABLE Reservations (Room VARCHAR); CREATE TABLE Rooms (decor VARCHAR, RoomId VARCHAR)

SELECT T2.decor FROM Reservations AS T1 JOIN Rooms AS T2 ON T1.Room = T2.RoomId GROUP BY T2.decor ORDER BY COUNT(T2.decor) LIMIT 1


Question: List how many times the number of people in the room reached the maximum occupancy of the room. The number of people include adults and kids.

Context: CREATE TABLE Rooms (RoomId VARCHAR, maxOccupancy VARCHAR); CREATE TABLE Reservations (Room VARCHAR, Adults VARCHAR, Kids VARCHAR)

SELECT COUNT(*) FROM Reservations AS T1 JOIN Rooms AS T2 ON T1.Room = T2.RoomId WHERE T2.maxOccupancy = T1.Adults + T1.Kids


Question: Find the first and last names of people who payed more than the rooms' base prices.

Context: CREATE TABLE Reservations (firstname VARCHAR, lastname VARCHAR, Room VARCHAR, Rate VARCHAR); CREATE TABLE Rooms (RoomId VARCHAR, basePrice VARCHAR)

SELECT T1.firstname, T1.lastname FROM Reservations AS T1 JOIN Rooms AS T2 ON T1.Room = T2.RoomId WHERE T1.Rate - T2.basePrice > 0


Question: How many rooms are there?

Context: CREATE TABLE Rooms (Id VARCHAR)


Question: Find the number of rooms with a king bed.

Context: CREATE TABLE Rooms (bedType VARCHAR)

SELECT COUNT(*) FROM Rooms WHERE bedType = "King"


Question: Find the number of rooms for each bed type.

Context: CREATE TABLE Rooms (bedType VARCHAR)

SELECT bedType, COUNT(*) FROM Rooms GROUP BY bedType


Question: Find the name of the room with the maximum occupancy.

Context: CREATE TABLE Rooms (roomName VARCHAR, maxOccupancy VARCHAR)

SELECT roomName FROM Rooms ORDER BY maxOccupancy DESC LIMIT 1


Question: Find the id and name of the most expensive base price room.

Context: CREATE TABLE Rooms (RoomId VARCHAR, roomName VARCHAR, basePrice VARCHAR)

SELECT RoomId, roomName FROM Rooms ORDER BY basePrice DESC LIMIT 1


Question: List the type of bed and name of all traditional rooms.

Context: CREATE TABLE Rooms (roomName VARCHAR, bedType VARCHAR, decor VARCHAR)

SELECT roomName, bedType FROM Rooms WHERE decor = "traditional"


Question: Find the number of rooms with king bed for each decor type.

Context: CREATE TABLE Rooms (decor VARCHAR, bedType VARCHAR)

SELECT decor, COUNT(*) FROM Rooms WHERE bedType = "King" GROUP BY decor


Question: Find the average and minimum price of the rooms in different decor.

Context: CREATE TABLE Rooms (decor VARCHAR, basePrice INTEGER)

SELECT decor, AVG(basePrice), MIN(basePrice) FROM Rooms GROUP BY decor


Question: List the name of all rooms sorted by their prices.

SELECT roomName FROM Rooms ORDER BY basePrice


Question: Find the number of rooms with price higher than 120 for different decor.

SELECT decor, COUNT(*) FROM Rooms WHERE basePrice > 120 GROUP BY decor


Question: List the name of rooms with king or queen bed.

Context: CREATE TABLE Rooms (roomName VARCHAR, bedType VARCHAR)

SELECT roomName FROM Rooms WHERE bedType = "King" OR bedType = "Queen"


Question: How many different types of beds are there?

Context: CREATE TABLE Rooms (bedType VARCHAR)

SELECT COUNT(DISTINCT bedType) FROM Rooms


Question: Find the name and id of the top 3 expensive rooms.

SELECT RoomId, roomName FROM Rooms ORDER BY basePrice DESC LIMIT 3


Question: Find the name of rooms whose price is higher than the average price.

Context: CREATE TABLE Rooms (roomName VARCHAR, basePrice INTEGER)

SELECT roomName FROM Rooms WHERE basePrice > (SELECT AVG(basePrice) FROM Rooms)


Question: Find the number of rooms that do not have any reservation.

Context: CREATE TABLE rooms (roomid VARCHAR, room VARCHAR); CREATE TABLE reservations (roomid VARCHAR, room VARCHAR)

SELECT COUNT(*) FROM rooms WHERE NOT roomid IN (SELECT DISTINCT room FROM reservations)


Question: Return the name and number of reservations made for each of the rooms.

Context: CREATE TABLE Reservations (Room VARCHAR); CREATE TABLE Rooms (roomName VARCHAR, RoomId VARCHAR)

SELECT T2.roomName, COUNT(*), T1.Room FROM Reservations AS T1 JOIN Rooms AS T2 ON T1.Room = T2.RoomId GROUP BY T1.Room


Question: Find the names of rooms that have been reserved for more than 60 times.

SELECT T2.roomName FROM Reservations AS T1 JOIN Rooms AS T2 ON T1.Room = T2.RoomId GROUP BY T1.Room HAVING COUNT(*) > 60


Question: Find the name of rooms whose base price is between 120 and 150.

Context: CREATE TABLE rooms (roomname VARCHAR, baseprice INTEGER)

SELECT roomname FROM rooms WHERE baseprice BETWEEN 120 AND 150


Question: Find the name of rooms booked by some customers whose first name contains ROY.

SELECT T2.roomName FROM Reservations AS T1 JOIN Rooms AS T2 ON T1.Room = T2.RoomId WHERE firstname LIKE '%ROY%'


Question: what are the details of the cmi masters that have the cross reference code 'Tax'?

Context: CREATE TABLE CMI_Cross_References (master_customer_id VARCHAR, source_system_code VARCHAR); CREATE TABLE Customer_Master_Index (cmi_details VARCHAR, master_customer_id VARCHAR)

SELECT T1.cmi_details FROM Customer_Master_Index AS T1 JOIN CMI_Cross_References AS T2 ON T1.master_customer_id = T2.master_customer_id WHERE T2.source_system_code = 'Tax'


Question: What is the cmi cross reference id that is related to at least one council tax entry? List the cross reference id and source system code.

Context: CREATE TABLE Council_Tax (cmi_cross_ref_id VARCHAR); CREATE TABLE CMI_Cross_References (cmi_cross_ref_id VARCHAR, source_system_code VARCHAR)

SELECT T1.cmi_cross_ref_id, T1.source_system_code FROM CMI_Cross_References AS T1 JOIN Council_Tax AS T2 ON T1.cmi_cross_ref_id = T2.cmi_cross_ref_id GROUP BY T1.cmi_cross_ref_id HAVING COUNT(*) >= 1


Question: How many business rates are related to each cmi cross reference? List cross reference id, master customer id and the n

Context: CREATE TABLE CMI_Cross_References (cmi_cross_ref_id VARCHAR, master_customer_id VARCHAR); CREATE TABLE Business_Rates (cmi_cross_ref_id VARCHAR)

SELECT T2.cmi_cross_ref_id, T2.master_customer_id, COUNT(*) FROM Business_Rates AS T1 JOIN CMI_Cross_References AS T2 ON T1.cmi_cross_ref_id = T2.cmi_cross_ref_id GROUP BY T2.cmi_cross_ref_id


Question: What is the tax source system code related to the benefits and overpayments? List the code and the benifit id, order by benifit id.

Context: CREATE TABLE CMI_Cross_References (source_system_code VARCHAR, cmi_cross_ref_id VARCHAR); CREATE TABLE Benefits_Overpayments (council_tax_id VARCHAR, cmi_cross_ref_id VARCHAR)

SELECT T1.source_system_code, T2.council_tax_id FROM CMI_Cross_References AS T1 JOIN Benefits_Overpayments AS T2 ON T1.cmi_cross_ref_id = T2.cmi_cross_ref_id ORDER BY T2.council_tax_id


Question: Wat is the tax source system code and master customer id of the taxes related to each parking fine id?

Context: CREATE TABLE CMI_Cross_References (source_system_code VARCHAR, master_customer_id VARCHAR, cmi_cross_ref_id VARCHAR); CREATE TABLE Parking_Fines (council_tax_id VARCHAR, cmi_cross_ref_id VARCHAR)

SELECT T1.source_system_code, T1.master_customer_id, T2.council_tax_id FROM CMI_Cross_References AS T1 JOIN Parking_Fines AS T2 ON T1.cmi_cross_ref_id = T2.cmi_cross_ref_id


Question: What are the renting arrears tax ids related to the customer master index whose detail is not 'Schmidt, Kertzmann and Lubowitz'?

Context: CREATE TABLE Rent_Arrears (council_tax_id VARCHAR, cmi_cross_ref_id VARCHAR); CREATE TABLE Customer_Master_Index (master_customer_id VARCHAR, cmi_details VARCHAR); CREATE TABLE CMI_Cross_References (cmi_cross_ref_id VARCHAR, master_customer_id VARCHAR)

SELECT T1.council_tax_id FROM Rent_Arrears AS T1 JOIN CMI_Cross_References AS T2 ON T1.cmi_cross_ref_id = T2.cmi_cross_ref_id JOIN Customer_Master_Index AS T3 ON T3.master_customer_id = T2.master_customer_id WHERE T3.cmi_details <> 'Schmidt ,  Kertzmann and Lubowitz'


Question: What are the register ids of electoral registries that have the cross reference source system code 'Electoral' or 'Tax'?

Context: CREATE TABLE Electoral_Register (electoral_register_id VARCHAR, cmi_cross_ref_id VARCHAR); CREATE TABLE CMI_Cross_References (cmi_cross_ref_id VARCHAR, source_system_code VARCHAR)

SELECT T1.electoral_register_id FROM Electoral_Register AS T1 JOIN CMI_Cross_References AS T2 ON T1.cmi_cross_ref_id = T2.cmi_cross_ref_id WHERE T2.source_system_code = 'Electoral' OR T2.source_system_code = 'Tax'


Question: How many different source system code for the cmi cross references are there?

Context: CREATE TABLE CMI_cross_references (source_system_code VARCHAR)

SELECT COUNT(DISTINCT source_system_code) FROM CMI_cross_references


Question: List all information about customer master index, and sort them by details in descending order.

Context: CREATE TABLE customer_master_index (cmi_details VARCHAR)

SELECT * FROM customer_master_index ORDER BY cmi_details DESC


Question: List the council tax ids and their related cmi cross references of all the parking fines.

Context: CREATE TABLE parking_fines (council_tax_id VARCHAR, cmi_cross_ref_id VARCHAR)

SELECT council_tax_id, cmi_cross_ref_id FROM parking_fines


Question: How many council taxes are collected for renting arrears ?

Context: CREATE TABLE rent_arrears (Id VARCHAR)


Question: What are the distinct cross reference source system codes which are related to the master customer details 'Gottlieb, Becker and Wyman'?

Context: CREATE TABLE customer_master_index (master_customer_id VARCHAR, cmi_details VARCHAR); CREATE TABLE cmi_cross_references (source_system_code VARCHAR, master_customer_id VARCHAR)

SELECT DISTINCT T2.source_system_code FROM customer_master_index AS T1 JOIN cmi_cross_references AS T2 ON T1.master_customer_id = T2.master_customer_id WHERE T1.cmi_details = 'Gottlieb ,  Becker and Wyman'


Question: Which cmi cross reference id is not related to any parking taxes?

Context: CREATE TABLE parking_fines (cmi_cross_ref_id VARCHAR); CREATE TABLE cmi_cross_references (cmi_cross_ref_id VARCHAR)

SELECT cmi_cross_ref_id FROM cmi_cross_references EXCEPT SELECT cmi_cross_ref_id FROM parking_fines


Question: Which distinct source system code includes the substring 'en'?

Context: CREATE TABLE cmi_cross_references (source_system_code VARCHAR)

SELECT DISTINCT source_system_code FROM cmi_cross_references WHERE source_system_code LIKE '%en%'


Question: How many parties are there?

Context: CREATE TABLE party (Id VARCHAR)


Question: List the themes of parties in ascending order of number of hosts.

Context: CREATE TABLE party (Party_Theme VARCHAR, Number_of_hosts VARCHAR)

SELECT Party_Theme FROM party ORDER BY Number_of_hosts


Question: What are the themes and locations of parties?

Context: CREATE TABLE party (Party_Theme VARCHAR, LOCATION VARCHAR)


Question: Show the first year and last year of parties with theme "Spring" or "Teqnology".

Context: CREATE TABLE party (First_year VARCHAR, Last_year VARCHAR, Party_Theme VARCHAR)

SELECT First_year, Last_year FROM party WHERE Party_Theme = "Spring" OR Party_Theme = "Teqnology"


Question: What is the average number of hosts for parties?

Context: CREATE TABLE party (Number_of_hosts INTEGER)


Question: What is the location of the party with the most hosts?

Context: CREATE TABLE party (LOCATION VARCHAR, Number_of_hosts VARCHAR)

SELECT LOCATION FROM party ORDER BY Number_of_hosts DESC LIMIT 1


Question: Show different nationalities along with the number of hosts of each nationality.

Context: CREATE TABLE HOST (Nationality VARCHAR)

SELECT Nationality, COUNT(*) FROM HOST GROUP BY Nationality


Question: Show the most common nationality of hosts.

Context: CREATE TABLE HOST (Nationality VARCHAR)

SELECT Nationality FROM HOST GROUP BY Nationality ORDER BY COUNT(*) DESC LIMIT 1


Question: Show the nations that have both hosts older than 45 and hosts younger than 35.

Context: CREATE TABLE HOST (Nationality VARCHAR, Age INTEGER)

SELECT Nationality FROM HOST WHERE Age > 45 INTERSECT SELECT Nationality FROM HOST WHERE Age < 35


Question: Show the themes of parties and the names of the party hosts.

Context: CREATE TABLE HOST (Name VARCHAR, Host_ID VARCHAR); CREATE TABLE party_host (Host_ID VARCHAR, Party_ID VARCHAR); CREATE TABLE party (Party_Theme VARCHAR, Party_ID VARCHAR)

SELECT T3.Party_Theme, T2.Name FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID


Question: Show the locations of parties and the names of the party hosts in ascending order of the age of the host.

Context: CREATE TABLE party (Location VARCHAR, Party_ID VARCHAR); CREATE TABLE HOST (Name VARCHAR, Host_ID VARCHAR, Age VARCHAR); CREATE TABLE party_host (Host_ID VARCHAR, Party_ID VARCHAR)

SELECT T3.Location, T2.Name FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID ORDER BY T2.Age


Question: Show the locations of parties with hosts older than 50.

Context: CREATE TABLE party (Location VARCHAR, Party_ID VARCHAR); CREATE TABLE party_host (Host_ID VARCHAR, Party_ID VARCHAR); CREATE TABLE HOST (Host_ID VARCHAR, Age INTEGER)

SELECT T3.Location FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID WHERE T2.Age > 50


Question: Show the host names for parties with number of hosts greater than 20.

Context: CREATE TABLE HOST (Name VARCHAR, Host_ID VARCHAR); CREATE TABLE party_host (Host_ID VARCHAR, Party_ID VARCHAR); CREATE TABLE party (Party_ID VARCHAR, Number_of_hosts INTEGER)

SELECT T2.Name FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID WHERE T3.Number_of_hosts > 20


Question: Show the name and the nationality of the oldest host.

Context: CREATE TABLE HOST (Name VARCHAR, Nationality VARCHAR, Age VARCHAR)

SELECT Name, Nationality FROM HOST ORDER BY Age DESC LIMIT 1


Question: List the names of hosts who did not serve as a host of any party in our record.

Context: CREATE TABLE HOST (Name VARCHAR, Host_ID VARCHAR); CREATE TABLE party_host (Name VARCHAR, Host_ID VARCHAR)

SELECT Name FROM HOST WHERE NOT Host_ID IN (SELECT Host_ID FROM party_host)


Question: Show all region code and region name sorted by the codes.

Context: CREATE TABLE region (region_code VARCHAR, region_name VARCHAR)

SELECT region_code, region_name FROM region ORDER BY region_code


Question: List all region names in alphabetical order.

Context: CREATE TABLE region (region_name VARCHAR)

SELECT region_name FROM region ORDER BY region_name


Question: Show names for all regions except for Denmark.

SELECT region_name FROM region WHERE region_name <> 'Denmark'


Question: How many storms had death records?

Context: CREATE TABLE storm (Number_Deaths INTEGER)

SELECT COUNT(*) FROM storm WHERE Number_Deaths > 0


Question: List name, dates active, and number of deaths for all storms with at least 1 death.

Context: CREATE TABLE storm (name VARCHAR, dates_active VARCHAR, number_deaths VARCHAR)

SELECT name, dates_active, number_deaths FROM storm WHERE number_deaths >= 1


Question: Show the average and maximum damage for all storms with max speed higher than 1000.

Context: CREATE TABLE storm (damage_millions_USD INTEGER, max_speed INTEGER)

SELECT AVG(damage_millions_USD), MAX(damage_millions_USD) FROM storm WHERE max_speed > 1000


Question: What is the total number of deaths and damage for all storms with a max speed greater than the average?

Context: CREATE TABLE storm (number_deaths INTEGER, damage_millions_USD INTEGER, max_speed INTEGER)

SELECT SUM(number_deaths), SUM(damage_millions_USD) FROM storm WHERE max_speed > (SELECT AVG(max_speed) FROM storm)


Question: List name and damage for all storms in a descending order of max speed.

Context: CREATE TABLE storm (name VARCHAR, damage_millions_USD VARCHAR, max_speed VARCHAR)

SELECT name, damage_millions_USD FROM storm ORDER BY max_speed DESC


Question: How many regions are affected?

Context: CREATE TABLE affected_region (region_id VARCHAR)

SELECT COUNT(DISTINCT region_id) FROM affected_region


Question: Show the name for regions not affected.

Context: CREATE TABLE region (region_name VARCHAR, region_id VARCHAR); CREATE TABLE affected_region (region_name VARCHAR, region_id VARCHAR)

SELECT region_name FROM region WHERE NOT region_id IN (SELECT region_id FROM affected_region)


Question: Show the name for regions and the number of storms for each region.

Context: CREATE TABLE region (region_name VARCHAR, region_id VARCHAR); CREATE TABLE affected_region (region_id VARCHAR)

SELECT T1.region_name, COUNT(*) FROM region AS T1 JOIN affected_region AS T2 ON T1.region_id = T2.region_id GROUP BY T1.region_id


Question: List the name for storms and the number of affected regions for each storm.

Context: CREATE TABLE affected_region (storm_id VARCHAR); CREATE TABLE storm (name VARCHAR, storm_id VARCHAR)

SELECT T1.name, COUNT(*) FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id


Question: What is the storm name and max speed which affected the greatest number of regions?

Context: CREATE TABLE storm (name VARCHAR, max_speed VARCHAR, storm_id VARCHAR); CREATE TABLE affected_region (storm_id VARCHAR)

SELECT T1.name, T1.max_speed FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Show the name of storms which don't have affected region in record.

Context: CREATE TABLE affected_region (name VARCHAR, storm_id VARCHAR); CREATE TABLE storm (name VARCHAR, storm_id VARCHAR)

SELECT name FROM storm WHERE NOT storm_id IN (SELECT storm_id FROM affected_region)


Question: Show storm name with at least two regions and 10 cities affected.

Context: CREATE TABLE affected_region (storm_id VARCHAR, number_city_affected INTEGER); CREATE TABLE storm (name VARCHAR, storm_id VARCHAR)

SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING COUNT(*) >= 2 INTERSECT SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING SUM(T2.number_city_affected) >= 10


Question: Show all storm names except for those with at least two affected regions.

Context: CREATE TABLE storm (name VARCHAR); CREATE TABLE affected_region (storm_id VARCHAR); CREATE TABLE storm (name VARCHAR, storm_id VARCHAR)

SELECT name FROM storm EXCEPT SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING COUNT(*) >= 2


Question: What are the region names affected by the storm with a number of deaths of least 10?

Context: CREATE TABLE region (region_name VARCHAR, region_id VARCHAR); CREATE TABLE affected_region (region_id VARCHAR, storm_id VARCHAR); CREATE TABLE storm (storm_id VARCHAR, number_deaths VARCHAR)

SELECT T2.region_name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T3.number_deaths >= 10


Question: Show all storm names affecting region "Denmark".

Context: CREATE TABLE region (region_id VARCHAR, region_name VARCHAR); CREATE TABLE affected_region (region_id VARCHAR, storm_id VARCHAR); CREATE TABLE storm (name VARCHAR, storm_id VARCHAR)

SELECT T3.name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T2.region_name = 'Denmark'


Question: Show the region name with at least two storms.

SELECT T1.region_name FROM region AS T1 JOIN affected_region AS T2 ON T1.region_id = T2.region_id GROUP BY T1.region_id HAVING COUNT(*) >= 2


Question: Find the names of the regions which were affected by the storm that killed the greatest number of people.

Context: CREATE TABLE region (region_name VARCHAR, region_id VARCHAR); CREATE TABLE affected_region (region_id VARCHAR, storm_id VARCHAR); CREATE TABLE storm (storm_id VARCHAR, Number_Deaths VARCHAR)

SELECT T2.region_name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id ORDER BY T3.Number_Deaths DESC LIMIT 1


Question: Find the name of the storm that affected both Afghanistan and Albania regions.

Context: CREATE TABLE storm (Name VARCHAR, storm_id VARCHAR); CREATE TABLE affected_region (region_id VARCHAR, storm_id VARCHAR); CREATE TABLE region (region_id VARCHAR, Region_name VARCHAR)

SELECT T3.Name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T2.Region_name = 'Afghanistan' INTERSECT SELECT T3.Name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T2.Region_name = 'Albania'


Question: How many counties are there in total?

Context: CREATE TABLE county (Id VARCHAR)


Question: Show the county name and population of all counties.

Context: CREATE TABLE county (County_name VARCHAR, Population VARCHAR)

SELECT County_name, Population FROM county


Question: Show the average population of all counties.

Context: CREATE TABLE county (Population INTEGER)


Question: Return the maximum and minimum population among all counties.

SELECT MAX(Population), MIN(Population) FROM county


Question: Show all the distinct districts for elections.

Context: CREATE TABLE election (District VARCHAR)


Question: Show the zip code of the county with name "Howard".

Context: CREATE TABLE county (Zip_code VARCHAR, County_name VARCHAR)

SELECT Zip_code FROM county WHERE County_name = "Howard"


Question: Show the delegate from district 1 in election.

Context: CREATE TABLE election (Delegate VARCHAR, District VARCHAR)

SELECT Delegate FROM election WHERE District = 1


Question: Show the delegate and committee information of elections.

Context: CREATE TABLE election (Delegate VARCHAR, Committee VARCHAR)

SELECT Delegate, Committee FROM election


Question: How many distinct governors are there?

Context: CREATE TABLE party (Governor VARCHAR)

SELECT COUNT(DISTINCT Governor) FROM party


Question: Show the lieutenant governor and comptroller from the democratic party.

Context: CREATE TABLE party (Lieutenant_Governor VARCHAR, Comptroller VARCHAR, Party VARCHAR)

SELECT Lieutenant_Governor, Comptroller FROM party WHERE Party = "Democratic"


Question: In which distinct years was the governor "Eliot Spitzer"?

Context: CREATE TABLE party (YEAR VARCHAR, Governor VARCHAR)

SELECT DISTINCT YEAR FROM party WHERE Governor = "Eliot Spitzer"


Question: Show all the information about election.

Context: CREATE TABLE election (Id VARCHAR)


Question: Show the delegates and the names of county they belong to.

Context: CREATE TABLE election (Delegate VARCHAR, District VARCHAR); CREATE TABLE county (County_name VARCHAR, County_id VARCHAR)

SELECT T2.Delegate, T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District


Question: Which delegates are from counties with population smaller than 100000?

Context: CREATE TABLE election (Delegate VARCHAR, District VARCHAR); CREATE TABLE county (County_id VARCHAR, Population INTEGER)

SELECT T2.Delegate FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District WHERE T1.Population < 100000


Question: How many distinct delegates are from counties with population larger than 50000?

SELECT COUNT(DISTINCT T2.Delegate) FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District WHERE T1.Population > 50000


Question: What are the names of the county that the delegates on "Appropriations" committee belong to?

Context: CREATE TABLE election (District VARCHAR, Committee VARCHAR); CREATE TABLE county (County_name VARCHAR, County_id VARCHAR)

SELECT T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District WHERE T2.Committee = "Appropriations"


Question: Show the delegates and the names of the party they belong to.

Context: CREATE TABLE election (Delegate VARCHAR, Party VARCHAR); CREATE TABLE party (Party VARCHAR, Party_ID VARCHAR)

SELECT T1.Delegate, T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID


Question: Who were the governors of the parties associated with delegates from district 1?

Context: CREATE TABLE party (Governor VARCHAR, Party_ID VARCHAR); CREATE TABLE election (Party VARCHAR, District VARCHAR)

SELECT T2.Governor FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.District = 1


Question: Who were the comptrollers of the parties associated with the delegates from district 1 or district 2?

Context: CREATE TABLE party (Comptroller VARCHAR, Party_ID VARCHAR); CREATE TABLE election (Party VARCHAR, District VARCHAR)

SELECT T2.Comptroller FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.District = 1 OR T1.District = 2


Question: Return all the committees that have delegates from Democratic party.

Context: CREATE TABLE election (Committee VARCHAR, Party VARCHAR); CREATE TABLE party (Party_ID VARCHAR, Party VARCHAR)

SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Democratic"


Question: Show the name of each county along with the corresponding number of delegates from that county.

Context: CREATE TABLE election (District VARCHAR); CREATE TABLE county (County_name VARCHAR, County_id VARCHAR)

SELECT T1.County_name, COUNT(*) FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District GROUP BY T1.County_id


Question: Show the name of each party and the corresponding number of delegates from that party.

Context: CREATE TABLE election (Party VARCHAR); CREATE TABLE party (Party VARCHAR, Party_ID VARCHAR)

SELECT T2.Party, COUNT(*) FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID GROUP BY T1.Party


Question: Return the names of all counties sorted by population in ascending order.

Context: CREATE TABLE county (County_name VARCHAR, Population VARCHAR)

SELECT County_name FROM county ORDER BY Population


Question: Return the names of all counties sorted by county name in descending alphabetical order.

Context: CREATE TABLE county (County_name VARCHAR)

SELECT County_name FROM county ORDER BY County_name DESC


Question: Show the name of the county with the biggest population.

SELECT County_name FROM county ORDER BY Population DESC LIMIT 1


Question: Show the 3 counties with the smallest population.

SELECT County_name FROM county ORDER BY Population LIMIT 3


Question: Show the names of counties that have at least two delegates.

SELECT T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District GROUP BY T1.County_id HAVING COUNT(*) >= 2


Question: Show the name of the party that has at least two records.

Context: CREATE TABLE party (Party VARCHAR)

SELECT Party FROM party GROUP BY Party HAVING COUNT(*) >= 2


Question: Show the name of the party that has the most delegates.

SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID GROUP BY T1.Party ORDER BY COUNT(*) DESC LIMIT 1


Question: Show the people that have been governor the most times.

Context: CREATE TABLE party (Governor VARCHAR)

SELECT Governor FROM party GROUP BY Governor ORDER BY COUNT(*) DESC LIMIT 1


Question: Show the people that have been comptroller the most times and the corresponding number of times.

Context: CREATE TABLE party (Comptroller VARCHAR)

SELECT Comptroller, COUNT(*) FROM party GROUP BY Comptroller ORDER BY COUNT(*) DESC LIMIT 1


Question: What are the names of parties that do not have delegates in election?

Context: CREATE TABLE election (Party VARCHAR, Party_ID VARCHAR); CREATE TABLE party (Party VARCHAR, Party_ID VARCHAR)

SELECT Party FROM party WHERE NOT Party_ID IN (SELECT Party FROM election)


Question: What are the names of parties that have both delegates on "Appropriations" committee and

Context: CREATE TABLE election (Party VARCHAR, Committee VARCHAR); CREATE TABLE party (Party VARCHAR, Party_ID VARCHAR)

SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.Committee = "Appropriations" INTERSECT SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.Committee = "Economic Matters"


Question: Which committees have delegates from both democratic party and liberal party?

SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Democratic" INTERSECT SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Liberal"


Question: How many journalists are there?

Context: CREATE TABLE journalist (Id VARCHAR)


Question: List the names of journalists in ascending order of years working.

Context: CREATE TABLE journalist (Name VARCHAR, Years_working VARCHAR)

SELECT Name FROM journalist ORDER BY Years_working


Question: What are the nationalities and ages of journalists?

Context: CREATE TABLE journalist (Nationality VARCHAR, Age VARCHAR)


Question: Show the names of journalists from "England" or "Wales".

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

SELECT Name FROM journalist WHERE Nationality = "England" OR Nationality = "Wales"


Question: What is the average number of years spent working as a journalist?

Context: CREATE TABLE journalist (Years_working INTEGER)

SELECT AVG(Years_working) FROM journalist


Question: What is the nationality of the journalist with the largest number of years working?

Context: CREATE TABLE journalist (Nationality VARCHAR, Years_working VARCHAR)

SELECT Nationality FROM journalist ORDER BY Years_working DESC LIMIT 1


Question: Show the different nationalities and the number of journalists of each nationality.

Context: CREATE TABLE journalist (Nationality VARCHAR)

SELECT Nationality, COUNT(*) FROM journalist GROUP BY Nationality


Question: Show the most common nationality for journalists.

SELECT Nationality FROM journalist GROUP BY Nationality ORDER BY COUNT(*) DESC LIMIT 1


Question: Show the nations that have both journalists with more than 10 years of working and journalists with less than 3 years of working.

Context: CREATE TABLE journalist (Nationality VARCHAR, Years_working INTEGER)

SELECT Nationality FROM journalist WHERE Years_working > 10 INTERSECT SELECT Nationality FROM journalist WHERE Years_working < 3


Question: Show the dates, places, and names of events in descending order of the attendance.

Context: CREATE TABLE event (Date VARCHAR, Name VARCHAR, venue VARCHAR, Event_Attendance VARCHAR)

SELECT Date, Name, venue FROM event ORDER BY Event_Attendance DESC


Question: Show the names of journalists and the dates of the events they reported.

Context: CREATE TABLE journalist (Name VARCHAR, journalist_ID VARCHAR); CREATE TABLE news_report (Event_ID VARCHAR, journalist_ID VARCHAR); CREATE TABLE event (Date VARCHAR, Event_ID VARCHAR)

SELECT T3.Name, T2.Date FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID


Question: Show the names of journalists and the names of the events they reported in ascending order

Context: CREATE TABLE journalist (Name VARCHAR, journalist_ID VARCHAR); CREATE TABLE news_report (Event_ID VARCHAR, journalist_ID VARCHAR); CREATE TABLE event (Name VARCHAR, Event_ID VARCHAR, Event_Attendance VARCHAR)

SELECT T3.Name, T2.Name FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID ORDER BY T2.Event_Attendance


Question: Show the names of journalists and the number of events they reported.

Context: CREATE TABLE journalist (Name VARCHAR, journalist_ID VARCHAR); CREATE TABLE news_report (Event_ID VARCHAR, journalist_ID VARCHAR); CREATE TABLE event (Event_ID VARCHAR)

SELECT T3.Name, COUNT(*) FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID GROUP BY T3.Name


Question: Show the names of journalists that have reported more than one event.

SELECT T3.Name FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID GROUP BY T3.Name HAVING COUNT(*) > 1


Question: List the names of journalists who have not reported any event.

Context: CREATE TABLE journalist (Name VARCHAR, journalist_ID VARCHAR); CREATE TABLE news_report (Name VARCHAR, journalist_ID VARCHAR)

SELECT Name FROM journalist WHERE NOT journalist_ID IN (SELECT journalist_ID FROM news_report)


Question: what are the average and maximum attendances of all events?

Context: CREATE TABLE event (Event_Attendance INTEGER)

SELECT AVG(Event_Attendance), MAX(Event_Attendance) FROM event


Question: Find the average age and experience working length of journalists working on different role type.

Context: CREATE TABLE news_report (work_type VARCHAR, journalist_id VARCHAR); CREATE TABLE journalist (age INTEGER, journalist_id VARCHAR)

SELECT AVG(t1.age), AVG(Years_working), t2.work_type FROM journalist AS t1 JOIN news_report AS t2 ON t1.journalist_id = t2.journalist_id GROUP BY t2.work_type


Question: List the event venues and names that have the top 2 most number of people attended.

Context: CREATE TABLE event (venue VARCHAR, name VARCHAR, Event_Attendance VARCHAR)

SELECT venue, name FROM event ORDER BY Event_Attendance DESC LIMIT 2


Question: Show me all the restaurants.

Context: CREATE TABLE Restaurant (ResName VARCHAR)


Question: What is the address of the restaurant Subway?

Context: CREATE TABLE Restaurant (Address VARCHAR, ResName VARCHAR)

SELECT Address FROM Restaurant WHERE ResName = "Subway"


Question: What is the rating of the restaurant Subway?

Context: CREATE TABLE Restaurant (Rating VARCHAR, ResName VARCHAR)

SELECT Rating FROM Restaurant WHERE ResName = "Subway"


Question: List all restaurant types.

Context: CREATE TABLE Restaurant_Type (ResTypeName VARCHAR)


Question: What is the description of the restaurant type Sandwich?

Context: CREATE TABLE Restaurant_Type (ResTypeDescription VARCHAR, ResTypeName VARCHAR)

SELECT ResTypeDescription FROM Restaurant_Type WHERE ResTypeName = "Sandwich"


Question: Which restaurants have highest rating? List the restaurant name and its rating.

Context: CREATE TABLE Restaurant (ResName VARCHAR, Rating VARCHAR)

SELECT ResName, Rating FROM Restaurant ORDER BY Rating DESC LIMIT 1


Question: What is the age of student Linda Smith?

Context: CREATE TABLE Student (Age VARCHAR, Fname VARCHAR, Lname VARCHAR)

SELECT Age FROM Student WHERE Fname = "Linda" AND Lname = "Smith"


Question: What is the gender of the student Linda Smith?

Context: CREATE TABLE Student (Sex VARCHAR, Fname VARCHAR, Lname VARCHAR)

SELECT Sex FROM Student WHERE Fname = "Linda" AND Lname = "Smith"


Question: List all students' first names and last names who majored in 600.

Context: CREATE TABLE Student (Fname VARCHAR, Lname VARCHAR, Major VARCHAR)

SELECT Fname, Lname FROM Student WHERE Major = 600


Question: Which city does student Linda Smith live in?

Context: CREATE TABLE Student (city_code VARCHAR, Fname VARCHAR, Lname VARCHAR)

SELECT city_code FROM Student WHERE Fname = "Linda" AND Lname = "Smith"


Question: Advisor 1121 has how many students?

Context: CREATE TABLE Student (Advisor VARCHAR)

SELECT COUNT(*) FROM Student WHERE Advisor = 1121


Question: Which Advisor has most of students? List advisor and the number of students.

Context: CREATE TABLE Student (Advisor VARCHAR)

SELECT Advisor, COUNT(*) FROM Student GROUP BY Advisor ORDER BY COUNT(Advisor) DESC LIMIT 1


Question: Which major has least number of students? List the major and the number of students.

Context: CREATE TABLE Student (Major VARCHAR)

SELECT Major, COUNT(*) FROM Student GROUP BY Major ORDER BY COUNT(Major) LIMIT 1


Question: Which major has between 2 and 30 number of students? List major and the number of students.

Context: CREATE TABLE Student (Major VARCHAR)

SELECT Major, COUNT(*) FROM Student GROUP BY Major HAVING COUNT(Major) BETWEEN 2 AND 30


Question: Which student's age is older than 18 and is majoring in 600? List each student's first and last name.

Context: CREATE TABLE Student (Fname VARCHAR, Lname VARCHAR, Age VARCHAR, Major VARCHAR)

SELECT Fname, Lname FROM Student WHERE Age > 18 AND Major = 600


Question: List all female students age is older than 18 who is not majoring in 600. List students' first name and last name.

Context: CREATE TABLE Student (Fname VARCHAR, Lname VARCHAR, Sex VARCHAR, Age VARCHAR, Major VARCHAR)

SELECT Fname, Lname FROM Student WHERE Age > 18 AND Major <> 600 AND Sex = 'F'


Question: How many restaurant is the Sandwich type restaurant?

Context: CREATE TABLE Type_Of_Restaurant (Id VARCHAR); CREATE TABLE Restaurant (Id VARCHAR); CREATE TABLE Restaurant_Type (Id VARCHAR)

SELECT COUNT(*) FROM Restaurant JOIN Type_Of_Restaurant ON Restaurant.ResID = Type_Of_Restaurant.ResID JOIN Restaurant_Type ON Type_Of_Restaurant.ResTypeID = Restaurant_Type.ResTypeID GROUP BY Type_Of_Restaurant.ResTypeID HAVING Restaurant_Type.ResTypeName = 'Sandwich'


Question: How long does student Linda Smith spend on the restaurant in total?

Context: CREATE TABLE Visits_Restaurant (Spent INTEGER); CREATE TABLE Student (Spent INTEGER)

SELECT SUM(Spent) FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID WHERE Student.Fname = "Linda" AND Student.Lname = "Smith"


Question: How many times has the student Linda Smith visited Subway?

Context: CREATE TABLE Visits_Restaurant (Id VARCHAR); CREATE TABLE Student (Id VARCHAR); CREATE TABLE Restaurant (Id VARCHAR)

SELECT COUNT(*) FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID JOIN Restaurant ON Visits_Restaurant.ResID = Restaurant.ResID WHERE Student.Fname = "Linda" AND Student.Lname = "Smith" AND Restaurant.ResName = "Subway"


Question: When did Linda Smith visit Subway?

Context: CREATE TABLE Restaurant (TIME VARCHAR); CREATE TABLE Visits_Restaurant (TIME VARCHAR); CREATE TABLE Student (TIME VARCHAR)

SELECT TIME FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID JOIN Restaurant ON Visits_Restaurant.ResID = Restaurant.ResID WHERE Student.Fname = "Linda" AND Student.Lname = "Smith" AND Restaurant.ResName = "Subway"


Question: At which restaurant did the students spend the least amount of time? List restaurant and the time students spent on in total.

Context: CREATE TABLE Visits_Restaurant (Id VARCHAR); CREATE TABLE Restaurant (Id VARCHAR)

SELECT Restaurant.ResName, SUM(Visits_Restaurant.Spent) FROM Visits_Restaurant JOIN Restaurant ON Visits_Restaurant.ResID = Restaurant.ResID GROUP BY Restaurant.ResID ORDER BY SUM(Visits_Restaurant.Spent) LIMIT 1


Question: Which student visited restaurant most often? List student's first name and last name.

Context: CREATE TABLE Visits_Restaurant (Id VARCHAR); CREATE TABLE Student (Id VARCHAR)

SELECT Student.Fname, Student.Lname FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID GROUP BY Student.StuID ORDER BY COUNT(*) DESC LIMIT 1


Question: Find the ids of orders whose status is 'Success'.

Context: CREATE TABLE actual_orders (actual_order_id VARCHAR, order_status_code VARCHAR)

SELECT actual_order_id FROM actual_orders WHERE order_status_code = 'Success'


Question: Find the name and price of the product that has been ordered the greatest number of times.

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

SELECT t1.product_name, t1.product_price FROM products AS t1 JOIN regular_order_products AS t2 ON t1.product_id = t2.product_id GROUP BY t2.product_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Find the number of customers in total.

Context: CREATE TABLE customers (Id VARCHAR)


Question: How many different payment methods are there?

Context: CREATE TABLE customers (payment_method VARCHAR)

SELECT COUNT(DISTINCT payment_method) FROM customers


Question: Show the details of all trucks in the order of their license number.

Context: CREATE TABLE trucks (truck_details VARCHAR, truck_licence_number VARCHAR)

SELECT truck_details FROM trucks ORDER BY truck_licence_number


Question: Find the name of the most expensive product.

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

SELECT product_name FROM products ORDER BY product_price DESC LIMIT 1


Question: Find the names of customers who are not living in the state of California.

Context: CREATE TABLE customer_addresses (customer_id VARCHAR, address_id VARCHAR); CREATE TABLE customers (customer_name VARCHAR, customer_id VARCHAR); CREATE TABLE customers (customer_name VARCHAR); CREATE TABLE addresses (address_id VARCHAR, state_province_county VARCHAR)

SELECT customer_name FROM customers EXCEPT SELECT t1.customer_name FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id WHERE t3.state_province_county = 'California'


Question: List the names and emails of customers who payed by Visa card.

Context: CREATE TABLE customers (customer_email VARCHAR, customer_name VARCHAR, payment_method VARCHAR)

SELECT customer_email, customer_name FROM customers WHERE payment_method = 'Visa'


Question: Find the names and phone numbers of customers living in California state.

Context: CREATE TABLE customer_addresses (customer_id VARCHAR, address_id VARCHAR); CREATE TABLE customers (customer_name VARCHAR, customer_phone VARCHAR, customer_id VARCHAR); CREATE TABLE addresses (address_id VARCHAR, state_province_county VARCHAR)

SELECT t1.customer_name, t1.customer_phone FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id WHERE t3.state_province_county = 'California'


Question: Find the states which do not have any employee in their record.

Context: CREATE TABLE Employees (state_province_county VARCHAR, address_id VARCHAR, employee_address_id VARCHAR); CREATE TABLE addresses (state_province_county VARCHAR, address_id VARCHAR, employee_address_id VARCHAR)

SELECT state_province_county FROM addresses WHERE NOT address_id IN (SELECT employee_address_id FROM Employees)


Question: List the names, phone numbers, and emails of all customers sorted by their dates of becoming customers.

Context: CREATE TABLE Customers (customer_name VARCHAR, customer_phone VARCHAR, customer_email VARCHAR, date_became_customer VARCHAR)

SELECT customer_name, customer_phone, customer_email FROM Customers ORDER BY date_became_customer


Question: Find the name of the first 5 customers.

Context: CREATE TABLE Customers (customer_name VARCHAR, date_became_customer VARCHAR)

SELECT customer_name FROM Customers ORDER BY date_became_customer LIMIT 5


Question: Find the payment method that is used most frequently.

Context: CREATE TABLE Customers (payment_method VARCHAR)

SELECT payment_method FROM Customers GROUP BY payment_method ORDER BY COUNT(*) DESC LIMIT 1


Question: List the names of all routes in alphabetic order.

Context: CREATE TABLE Delivery_Routes (route_name VARCHAR)

SELECT route_name FROM Delivery_Routes ORDER BY route_name


Question: Find the name of route that has the highest number of deliveries.

Context: CREATE TABLE Delivery_Routes (route_name VARCHAR, route_id VARCHAR); CREATE TABLE Delivery_Route_Locations (route_id VARCHAR)

SELECT t1.route_name FROM Delivery_Routes AS t1 JOIN Delivery_Route_Locations AS t2 ON t1.route_id = t2.route_id GROUP BY t1.route_id ORDER BY COUNT(*) DESC LIMIT 1


Question: List the state names and the number of customers living in each state.

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

SELECT t2.state_province_county, COUNT(*) FROM customer_addresses AS t1 JOIN addresses AS t2 ON t1.address_id = t2.address_id GROUP BY t2.state_province_county


Question: How many authors are there?

Context: CREATE TABLE authors (Id VARCHAR)


Question: How many institutions are there?

Context: CREATE TABLE inst (Id VARCHAR)


Question: How many papers are published in total?

Context: CREATE TABLE papers (Id VARCHAR)


Question: What are the titles of papers published by "Jeremy Gibbons"?

Context: CREATE TABLE authorship (authid VARCHAR, paperid VARCHAR); CREATE TABLE papers (title VARCHAR, paperid VARCHAR); CREATE TABLE authors (authid VARCHAR, fname VARCHAR, lname VARCHAR)

SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Jeremy" AND t1.lname = "Gibbons"


Question: Find all the papers published by "Aaron Turon".

SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Aaron" AND t1.lname = "Turon"


Question: How many papers have "Atsushi Ohori" published?

Context: CREATE TABLE authorship (authid VARCHAR, paperid VARCHAR); CREATE TABLE authors (authid VARCHAR, fname VARCHAR, lname VARCHAR); CREATE TABLE papers (paperid VARCHAR)

SELECT COUNT(*) FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Atsushi" AND t1.lname = "Ohori"


Question: What is the name of the institution that "Matthias Blume" belongs to?

Context: CREATE TABLE authorship (authid VARCHAR, instid VARCHAR); CREATE TABLE authors (authid VARCHAR, fname VARCHAR, lname VARCHAR); CREATE TABLE inst (name VARCHAR, instid VARCHAR)

SELECT DISTINCT t3.name FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t1.fname = "Matthias" AND t1.lname = "Blume"


Question: Which institution does "Katsuhiro Ueno" belong to?

SELECT DISTINCT t3.name FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t1.fname = "Katsuhiro" AND t1.lname = "Ueno"


Question: Who belong to the institution "University of Oxford"? Show the first names and last names.

Context: CREATE TABLE authorship (authid VARCHAR, instid VARCHAR); CREATE TABLE authors (fname VARCHAR, lname VARCHAR, authid VARCHAR); CREATE TABLE inst (instid VARCHAR, name VARCHAR)

SELECT DISTINCT t1.fname, t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "University of Oxford"


Question: Which authors belong to the institution "Google"? Show the first names and last names.

SELECT DISTINCT t1.fname, t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Google"


Question: What are the last names of the author of the paper titled "Binders Unbound"?

Context: CREATE TABLE authorship (authid VARCHAR, paperid VARCHAR); CREATE TABLE authors (lname VARCHAR, authid VARCHAR); CREATE TABLE papers (paperid VARCHAR, title VARCHAR)

SELECT t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t3.title = "Binders Unbound"


Question: Find the first and last name of the author(s) who wrote the paper "Nameless, Painless".

Context: CREATE TABLE authorship (authid VARCHAR, paperid VARCHAR); CREATE TABLE papers (paperid VARCHAR, title VARCHAR); CREATE TABLE authors (fname VARCHAR, lname VARCHAR, authid VARCHAR)

SELECT t1.fname, t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t3.title = "Nameless ,  Painless"


Question: What are the papers published under the institution "Indiana University"?

Context: CREATE TABLE inst (instid VARCHAR, name VARCHAR); CREATE TABLE authorship (paperid VARCHAR, instid VARCHAR); CREATE TABLE papers (title VARCHAR, paperid VARCHAR)

SELECT DISTINCT t1.title FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Indiana University"


Question: Find all the papers published by the institution "Google".

SELECT DISTINCT t1.title FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Google"


Question: How many papers are published by the institution "Tokohu University"?

SELECT COUNT(DISTINCT t1.title) FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Tokohu University"


Question: Find the number of papers published by the institution "University of Pennsylvania".

SELECT COUNT(DISTINCT t1.title) FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "University of Pennsylvania"


Question: Find the papers which have "Olin Shivers" as an author.

SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Olin" AND t1.lname = "Shivers"


Question: Which papers have "Stephanie Weirich" as an author?

SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Stephanie" AND t1.lname = "Weirich"


Question: Which paper is published in an institution in "USA" and have "Turon" as its second author?

Context: CREATE TABLE authorship (authid VARCHAR, paperid VARCHAR, instid VARCHAR, authorder VARCHAR); CREATE TABLE authors (authid VARCHAR, lname VARCHAR); CREATE TABLE papers (title VARCHAR, paperid VARCHAR); CREATE TABLE inst (instid VARCHAR, country VARCHAR)

SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid JOIN inst AS t4 ON t2.instid = t4.instid WHERE t4.country = "USA" AND t2.authorder = 2 AND t1.lname = "Turon"


Question: Find the titles of papers whose first author is affiliated with an institution in the country "Japan" and has last name "Ohori"?

SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid JOIN inst AS t4 ON t2.instid = t4.instid WHERE t4.country = "Japan" AND t2.authorder = 1 AND t1.lname = "Ohori"


Question: What is the last name of the author that has published the most papers?

Context: CREATE TABLE authorship (authid VARCHAR, paperid VARCHAR); CREATE TABLE authors (lname VARCHAR, fname VARCHAR, authid VARCHAR); CREATE TABLE papers (paperid VARCHAR)

SELECT t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid GROUP BY t1.fname, t1.lname ORDER BY COUNT(*) DESC LIMIT 1


Question: Retrieve the country that has published the most papers.

Context: CREATE TABLE inst (country VARCHAR, instid VARCHAR); CREATE TABLE authorship (instid VARCHAR, paperid VARCHAR); CREATE TABLE papers (paperid VARCHAR)

SELECT t1.country FROM inst AS t1 JOIN authorship AS t2 ON t1.instid = t2.instid JOIN papers AS t3 ON t2.paperid = t3.paperid GROUP BY t1.country ORDER BY COUNT(*) DESC LIMIT 1


Question: Find the name of the organization that has published the largest number of papers.

Context: CREATE TABLE inst (name VARCHAR, instid VARCHAR); CREATE TABLE authorship (instid VARCHAR, paperid VARCHAR); CREATE TABLE papers (paperid VARCHAR)

SELECT t1.name FROM inst AS t1 JOIN authorship AS t2 ON t1.instid = t2.instid JOIN papers AS t3 ON t2.paperid = t3.paperid GROUP BY t1.name ORDER BY COUNT(*) DESC LIMIT 1


Question: Find the titles of the papers that contain the word "ML".

Context: CREATE TABLE papers (title VARCHAR)

SELECT title FROM papers WHERE title LIKE "%ML%"


Question: Which paper's title contains the word "Database"?

Context: CREATE TABLE papers (title VARCHAR)

SELECT title FROM papers WHERE title LIKE "%Database%"


Question: Find the first names of all the authors who have written a paper with title containing the word "Functional".

Context: CREATE TABLE authors (fname VARCHAR, authid VARCHAR); CREATE TABLE papers (paperid VARCHAR, title VARCHAR); CREATE TABLE authorship (authid VARCHAR, paperid VARCHAR)

SELECT t1.fname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t3.title LIKE "%Functional%"


Question: Find the last names of all the authors that have written a paper with title containing the word "Monadic".

SELECT t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t3.title LIKE "%Monadic%"


Question: Retrieve the title of the paper that has the largest number of authors.

Context: CREATE TABLE authorship (authorder INTEGER); CREATE TABLE authorship (paperid VARCHAR, authorder INTEGER); CREATE TABLE papers (title VARCHAR, paperid VARCHAR)

SELECT t2.title FROM authorship AS t1 JOIN papers AS t2 ON t1.paperid = t2.paperid WHERE t1.authorder = (SELECT MAX(authorder) FROM authorship)


Question: What is the first name of the author with last name "Ueno"?

Context: CREATE TABLE authors (fname VARCHAR, lname VARCHAR)

SELECT fname FROM authors WHERE lname = "Ueno"


Question: Find the last name of the author with first name "Amal".

Context: CREATE TABLE authors (lname VARCHAR, fname VARCHAR)

SELECT lname FROM authors WHERE fname = "Amal"


Question: Find the first names of all the authors ordered in alphabetical order.

Context: CREATE TABLE authors (fname VARCHAR)

SELECT fname FROM authors ORDER BY fname


Question: Retrieve all the last names of authors in alphabetical order.

Context: CREATE TABLE authors (lname VARCHAR)

SELECT lname FROM authors ORDER BY lname


Question: Retrieve all the first and last names of authors in the alphabetical order of last names.

SELECT fname, lname FROM authors ORDER BY lname


Question: How many different last names do the actors and actresses have?

Context: CREATE TABLE actor (last_name VARCHAR)

SELECT COUNT(DISTINCT last_name) FROM actor


Question: What is the most popular first name of the actors?

Context: CREATE TABLE actor (first_name VARCHAR)

SELECT first_name FROM actor GROUP BY first_name ORDER BY COUNT(*) DESC LIMIT 1


Question: What is the most popular full name of the actors?

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

SELECT first_name, last_name FROM actor GROUP BY first_name, last_name ORDER BY COUNT(*) DESC LIMIT 1


Question: Which districts have at least two addresses?

Context: CREATE TABLE address (district VARCHAR)

SELECT district FROM address GROUP BY district HAVING COUNT(*) >= 2


Question: What is the phone number and postal code of the address 1031 Daugavpils Parkway?

Context: CREATE TABLE address (phone VARCHAR, postal_code VARCHAR, address VARCHAR)

SELECT phone, postal_code FROM address WHERE address = '1031 Daugavpils Parkway'


Question: Which city has the most addresses? List the city name, number of addresses, and city id.

Context: CREATE TABLE address (city_id VARCHAR); CREATE TABLE city (city VARCHAR, city_id VARCHAR)

SELECT T2.city, COUNT(*), T1.city_id FROM address AS T1 JOIN city AS T2 ON T1.city_id = T2.city_id GROUP BY T1.city_id ORDER BY COUNT(*) DESC LIMIT 1


Question: How many addresses are in the district of California?

Context: CREATE TABLE address (district VARCHAR)

SELECT COUNT(*) FROM address WHERE district = 'California'


Question: Which film is rented at a fee of 0.99 and has less than 3 in the inventory? List the film title and id.

Context: CREATE TABLE film (title VARCHAR, film_id VARCHAR, rental_rate VARCHAR); CREATE TABLE inventory (film_id VARCHAR); CREATE TABLE film (title VARCHAR, film_id VARCHAR)

SELECT title, film_id FROM film WHERE rental_rate = 0.99 INTERSECT SELECT T1.title, T1.film_id FROM film AS T1 JOIN inventory AS T2 ON T1.film_id = T2.film_id GROUP BY T1.film_id HAVING COUNT(*) < 3


Question: How many cities are in Australia?

Context: CREATE TABLE country (country_id VARCHAR, country VARCHAR); CREATE TABLE city (country_id VARCHAR)

SELECT COUNT(*) FROM city AS T1 JOIN country AS T2 ON T1.country_id = T2.country_id WHERE T2.country = 'Australia'


Question: Which countries have at least 3 cities?

Context: CREATE TABLE country (country VARCHAR, country_id VARCHAR); CREATE TABLE city (country_id VARCHAR)

SELECT T2.country FROM city AS T1 JOIN country AS T2 ON T1.country_id = T2.country_id GROUP BY T2.country_id HAVING COUNT(*) >= 3


Question: Find all the payment dates for the payments with an amount larger than 10 and the payments handled by a staff person with the first name Elsa.

Context: CREATE TABLE payment (payment_date VARCHAR, staff_id VARCHAR); CREATE TABLE staff (staff_id VARCHAR, first_name VARCHAR); CREATE TABLE payment (payment_date VARCHAR, amount INTEGER)

SELECT payment_date FROM payment WHERE amount > 10 UNION SELECT T1.payment_date FROM payment AS T1 JOIN staff AS T2 ON T1.staff_id = T2.staff_id WHERE T2.first_name = 'Elsa'


Question: How many customers have an active value of 1?

Context: CREATE TABLE customer (active VARCHAR)

SELECT COUNT(*) FROM customer WHERE active = '1'


Question: Which film has the highest rental rate? And what is the rate?

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

SELECT title, rental_rate FROM film ORDER BY rental_rate DESC LIMIT 1


Question: Which film has the most number of actors or actresses? List the film name, film id and description.

Context: CREATE TABLE film_actor (film_id VARCHAR); CREATE TABLE film (title VARCHAR, film_id VARCHAR, description VARCHAR)

SELECT T2.title, T2.film_id, T2.description FROM film_actor AS T1 JOIN film AS T2 ON T1.film_id = T2.film_id GROUP BY T2.film_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Which film actor (actress) starred the most films? List his or her first name, last name and actor id.

Context: CREATE TABLE film_actor (actor_id VARCHAR); CREATE TABLE actor (first_name VARCHAR, last_name VARCHAR, actor_id VARCHAR)

SELECT T2.first_name, T2.last_name, T2.actor_id FROM film_actor AS T1 JOIN actor AS T2 ON T1.actor_id = T2.actor_id GROUP BY T2.actor_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Which film actors (actresses) played a role in more than 30 films? List his or her first name and last name.

SELECT T2.first_name, T2.last_name FROM film_actor AS T1 JOIN actor AS T2 ON T1.actor_id = T2.actor_id GROUP BY T2.actor_id HAVING COUNT(*) > 30


Question: Which store owns most items?

Context: CREATE TABLE inventory (store_id VARCHAR)

SELECT store_id FROM inventory GROUP BY store_id ORDER BY COUNT(*) DESC LIMIT 1


Question: What is the total amount of all payments?

Context: CREATE TABLE payment (amount INTEGER)


Question: Which customer, who has made at least one payment, has spent the least money? List his or her first name, last name, and the id.

Context: CREATE TABLE payment (customer_id VARCHAR); CREATE TABLE customer (first_name VARCHAR, last_name VARCHAR, customer_id VARCHAR)

SELECT T1.first_name, T1.last_name, T1.customer_id FROM customer AS T1 JOIN payment AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY SUM(amount) LIMIT 1


Question: What is the genre name of the film HUNGER ROOF?

Context: CREATE TABLE film_category (category_id VARCHAR, film_id VARCHAR); CREATE TABLE film (film_id VARCHAR, title VARCHAR); CREATE TABLE category (name VARCHAR, category_id VARCHAR)

SELECT T1.name FROM category AS T1 JOIN film_category AS T2 ON T1.category_id = T2.category_id JOIN film AS T3 ON T2.film_id = T3.film_id WHERE T3.title = 'HUNGER ROOF'


Question: How many films are there in each category? List the genre name, genre id and the count.

Context: CREATE TABLE film_category (category_id VARCHAR); CREATE TABLE category (name VARCHAR, category_id VARCHAR)

SELECT T2.name, T1.category_id, COUNT(*) FROM film_category AS T1 JOIN category AS T2 ON T1.category_id = T2.category_id GROUP BY T1.category_id


Question: Which film has the most copies in the inventory? List both title and id.

Context: CREATE TABLE film (title VARCHAR, film_id VARCHAR); CREATE TABLE inventory (film_id VARCHAR)

SELECT T1.title, T1.film_id FROM film AS T1 JOIN inventory AS T2 ON T1.film_id = T2.film_id GROUP BY T1.film_id ORDER BY COUNT(*) DESC LIMIT 1


Question: What is the film title and inventory id of the item in the inventory which was rented most frequently?

Context: CREATE TABLE film (title VARCHAR, film_id VARCHAR); CREATE TABLE inventory (inventory_id VARCHAR, film_id VARCHAR); CREATE TABLE rental (inventory_id VARCHAR)

SELECT T1.title, T2.inventory_id FROM film AS T1 JOIN inventory AS T2 ON T1.film_id = T2.film_id JOIN rental AS T3 ON T2.inventory_id = T3.inventory_id GROUP BY T2.inventory_id ORDER BY COUNT(*) DESC LIMIT 1


Question: How many languages are in these films?

Context: CREATE TABLE film (language_id VARCHAR)

SELECT COUNT(DISTINCT language_id) FROM film


Question: What are all the movies rated as R? List the titles.

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

SELECT title FROM film WHERE rating = 'R'


Question: Where is store 1 located?

Context: CREATE TABLE store (address_id VARCHAR); CREATE TABLE address (address VARCHAR, address_id VARCHAR)

SELECT T2.address FROM store AS T1 JOIN address AS T2 ON T1.address_id = T2.address_id WHERE store_id = 1


Question: Which staff handled least number of payments? List the full name and the id.

Context: CREATE TABLE payment (staff_id VARCHAR); CREATE TABLE staff (first_name VARCHAR, last_name VARCHAR, staff_id VARCHAR)

SELECT T1.first_name, T1.last_name, T1.staff_id FROM staff AS T1 JOIN payment AS T2 ON T1.staff_id = T2.staff_id GROUP BY T1.staff_id ORDER BY COUNT(*) LIMIT 1


Question: Which language does the film AIRPORT POLLOCK use? List the language name.

Context: CREATE TABLE film (language_id VARCHAR, title VARCHAR); CREATE TABLE LANGUAGE (name VARCHAR, language_id VARCHAR)

SELECT T2.name FROM film AS T1 JOIN LANGUAGE AS T2 ON T1.language_id = T2.language_id WHERE T1.title = 'AIRPORT POLLOCK'


Question: How many stores are there?

Context: CREATE TABLE store (Id VARCHAR)


Question: How many kinds of different ratings are listed?

Context: CREATE TABLE film (rating VARCHAR)


Question: Which movies have 'Deleted Scenes' as a substring in the special feature?

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

SELECT title FROM film WHERE special_features LIKE '%Deleted Scenes%'


Question: How many items in inventory does store 1 have?

SELECT COUNT(*) FROM inventory WHERE store_id = 1


Question: When did the first payment happen?

Context: CREATE TABLE payment (payment_date VARCHAR)

SELECT payment_date FROM payment ORDER BY payment_date LIMIT 1


Question: Where does the customer with the first name Linda live? And what is her email?

Context: CREATE TABLE customer (email VARCHAR, address_id VARCHAR, first_name VARCHAR); CREATE TABLE address (address VARCHAR, address_id VARCHAR)

SELECT T2.address, T1.email FROM customer AS T1 JOIN address AS T2 ON T2.address_id = T1.address_id WHERE T1.first_name = 'LINDA'


Question: Find all the films longer than 100 minutes, or rated PG, except those who cost more than 200 for replacement. List the titles.

Context: CREATE TABLE film (title VARCHAR, replacement_cost INTEGER, LENGTH VARCHAR, rating VARCHAR)

SELECT title FROM film WHERE LENGTH > 100 OR rating = 'PG' EXCEPT SELECT title FROM film WHERE replacement_cost > 200


Question: What is the first name and the last name of the customer who made the earliest rental?

Context: CREATE TABLE customer (first_name VARCHAR, last_name VARCHAR, customer_id VARCHAR); CREATE TABLE rental (customer_id VARCHAR, rental_date VARCHAR)

SELECT T1.first_name, T1.last_name FROM customer AS T1 JOIN rental AS T2 ON T1.customer_id = T2.customer_id ORDER BY T2.rental_date LIMIT 1


Question: What is the full name of the staff member who has rented a film to a customer with the first name April and the last name Burns?

Context: CREATE TABLE customer (customer_id VARCHAR, first_name VARCHAR, last_name VARCHAR); CREATE TABLE rental (staff_id VARCHAR, customer_id VARCHAR); CREATE TABLE staff (first_name VARCHAR, last_name VARCHAR, staff_id VARCHAR)

SELECT DISTINCT T1.first_name, T1.last_name FROM staff AS T1 JOIN rental AS T2 ON T1.staff_id = T2.staff_id JOIN customer AS T3 ON T2.customer_id = T3.customer_id WHERE T3.first_name = 'APRIL' AND T3.last_name = 'BURNS'


Question: Which store has most the customers?

Context: CREATE TABLE customer (store_id VARCHAR)

SELECT store_id FROM customer GROUP BY store_id ORDER BY COUNT(*) DESC LIMIT 1


Question: What is the largest payment amount?

Context: CREATE TABLE payment (amount VARCHAR)

SELECT amount FROM payment ORDER BY amount DESC LIMIT 1


Question: Where does the staff member with the first name Elsa live?

Context: CREATE TABLE staff (address_id VARCHAR, first_name VARCHAR); CREATE TABLE address (address VARCHAR, address_id VARCHAR)

SELECT T2.address FROM staff AS T1 JOIN address AS T2 ON T1.address_id = T2.address_id WHERE T1.first_name = 'Elsa'


Question: What are the first names of customers who have not rented any films after '2005-08-23 02:06:01'?

Context: CREATE TABLE customer (first_name VARCHAR, customer_id VARCHAR, rental_date INTEGER); CREATE TABLE rental (first_name VARCHAR, customer_id VARCHAR, rental_date INTEGER)

SELECT first_name FROM customer WHERE NOT customer_id IN (SELECT customer_id FROM rental WHERE rental_date > '2005-08-23 02:06:01')


Question: How many bank branches are there?

Context: CREATE TABLE bank (Id VARCHAR)


Question: How many customers are there?

Context: CREATE TABLE bank (no_of_customers INTEGER)


Question: Find the number of customers in the banks at New York City.

Context: CREATE TABLE bank (no_of_customers INTEGER, city VARCHAR)

SELECT SUM(no_of_customers) FROM bank WHERE city = 'New York City'


Question: Find the average number of customers in all banks of Utah state.

Context: CREATE TABLE bank (no_of_customers INTEGER, state VARCHAR)

SELECT AVG(no_of_customers) FROM bank WHERE state = 'Utah'


Question: Find the average number of customers cross all banks.


Question: Find the city and state of the bank branch named morningside.

Context: CREATE TABLE bank (city VARCHAR, state VARCHAR, bname VARCHAR)

SELECT city, state FROM bank WHERE bname = 'morningside'


Question: Find the branch names of banks in the New York state.

Context: CREATE TABLE bank (bname VARCHAR, state VARCHAR)

SELECT bname FROM bank WHERE state = 'New York'


Question: List the name of all customers sorted by their account balance in ascending order.

Context: CREATE TABLE customer (cust_name VARCHAR, acc_bal VARCHAR)

SELECT cust_name FROM customer ORDER BY acc_bal


Question: List the name of all different customers who have some loan sorted by their total loan amount.

Context: CREATE TABLE loan (cust_id VARCHAR, amount INTEGER); CREATE TABLE customer (cust_name VARCHAR, cust_id VARCHAR)

SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name ORDER BY SUM(T2.amount)


Question: Find the state, account type, and credit score of the customer whose number of loan is 0.

Context: CREATE TABLE customer (state VARCHAR, acc_type VARCHAR, credit_score VARCHAR, no_of_loans VARCHAR)

SELECT state, acc_type, credit_score FROM customer WHERE no_of_loans = 0


Question: Find the number of different cities which banks are located at.

Context: CREATE TABLE bank (city VARCHAR)


Question: Find the number of different states which banks are located at.

Context: CREATE TABLE bank (state VARCHAR)


Question: How many distinct types of accounts are there?

Context: CREATE TABLE customer (acc_type VARCHAR)

SELECT COUNT(DISTINCT acc_type) FROM customer


Question: Find the name and account balance of the customer whose name includes the letter ‘a’.

SELECT cust_name, acc_bal FROM customer WHERE cust_name LIKE '%a%'


Question: Find the total account balance of each customer from Utah or Texas.

Context: CREATE TABLE customer (acc_bal INTEGER, state VARCHAR)

SELECT SUM(acc_bal) FROM customer WHERE state = 'Utah' OR state = 'Texas'


Question: Find the name of customers who have both saving and checking account types.

Context: CREATE TABLE customer (cust_name VARCHAR, acc_type VARCHAR)

SELECT cust_name FROM customer WHERE acc_type = 'saving' INTERSECT SELECT cust_name FROM customer WHERE acc_type = 'checking'


Question: Find the name of customers who do not have an saving account.

SELECT cust_name FROM customer EXCEPT SELECT cust_name FROM customer WHERE acc_type = 'saving'


Question: Find the name of customers who do not have a loan with a type of Mortgages.

Context: CREATE TABLE loan (cust_id VARCHAR, loan_type VARCHAR); CREATE TABLE customer (cust_name VARCHAR); CREATE TABLE customer (cust_name VARCHAR, cust_id VARCHAR)

SELECT cust_name FROM customer EXCEPT SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE T2.loan_type = 'Mortgages'


Question: Find the name of customers who have loans of both Mortgages and Auto.

Context: CREATE TABLE customer (cust_name VARCHAR, cust_id VARCHAR); CREATE TABLE loan (cust_id VARCHAR)

SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE loan_type = 'Mortgages' INTERSECT SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE loan_type = 'Auto'


Question: Find the name of customers whose credit score is below the average credit scores of all customers.

Context: CREATE TABLE customer (cust_name VARCHAR, credit_score INTEGER)

SELECT cust_name FROM customer WHERE credit_score < (SELECT AVG(credit_score) FROM customer)


Question: Find the branch name of the bank that has the most number of customers.

Context: CREATE TABLE bank (bname VARCHAR, no_of_customers VARCHAR)

SELECT bname FROM bank ORDER BY no_of_customers DESC LIMIT 1


Question: Find the name of customer who has the lowest credit score.

Context: CREATE TABLE customer (cust_name VARCHAR, credit_score VARCHAR)

SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1


Question: Find the name, account type, and account balance of the customer who has the highest credit score.

Context: CREATE TABLE customer (cust_name VARCHAR, acc_type VARCHAR, acc_bal VARCHAR, credit_score VARCHAR)

SELECT cust_name, acc_type, acc_bal FROM customer ORDER BY credit_score DESC LIMIT 1


Question: Find the name of customer who has the highest amount of loans.

SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name ORDER BY SUM(T2.amount) DESC LIMIT 1


Question: Find the state which has the most number of customers.

Context: CREATE TABLE bank (state VARCHAR, no_of_customers INTEGER)

SELECT state FROM bank GROUP BY state ORDER BY SUM(no_of_customers) DESC LIMIT 1


Question: For each account type, find the average account balance of customers with credit score lower than 50.

Context: CREATE TABLE customer (acc_type VARCHAR, acc_bal INTEGER, credit_score INTEGER)

SELECT AVG(acc_bal), acc_type FROM customer WHERE credit_score < 50 GROUP BY acc_type


Question: For each state, find the total account balance of customers whose credit score is above 100.

Context: CREATE TABLE customer (state VARCHAR, acc_bal INTEGER, credit_score INTEGER)

SELECT SUM(acc_bal), state FROM customer WHERE credit_score > 100 GROUP BY state


Question: Find the total amount of loans offered by each bank branch.

Context: CREATE TABLE loan (branch_id VARCHAR); CREATE TABLE bank (bname VARCHAR, branch_id VARCHAR)

SELECT SUM(amount), T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname


Question: Find the name of customers who have more than one loan.

SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name HAVING COUNT(*) > 1


Question: Find the name and account balance of the customers who have loans with a total amount of more than 5000.

Context: CREATE TABLE loan (cust_id VARCHAR, amount INTEGER); CREATE TABLE customer (cust_name VARCHAR, acc_type VARCHAR, cust_id VARCHAR)

SELECT T1.cust_name, T1.acc_type FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name HAVING SUM(T2.amount) > 5000


Question: Find the name of bank branch that provided the greatest total amount of loans.

Context: CREATE TABLE loan (branch_id VARCHAR, amount INTEGER); CREATE TABLE bank (bname VARCHAR, branch_id VARCHAR)

SELECT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname ORDER BY SUM(T2.amount) DESC LIMIT 1


Question: Find the name of bank branch that provided the greatest total amount of loans to customers with credit score is less than 100.

Context: CREATE TABLE loan (branch_id VARCHAR, cust_id VARCHAR, amount INTEGER); CREATE TABLE bank (bname VARCHAR, branch_id VARCHAR); CREATE TABLE customer (cust_id VARCHAR, credit_score INTEGER)

SELECT T2.bname FROM loan AS T1 JOIN bank AS T2 ON T1.branch_id = T2.branch_id JOIN customer AS T3 ON T1.cust_id = T3.cust_id WHERE T3.credit_score < 100 GROUP BY T2.bname ORDER BY SUM(T1.amount) DESC LIMIT 1


Question: Find the name of bank branches that provided some loans.

SELECT DISTINCT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id


Question: Find the name and credit score of the customers who have some loans.

Context: CREATE TABLE customer (cust_name VARCHAR, credit_score VARCHAR, cust_id VARCHAR); CREATE TABLE loan (cust_id VARCHAR)

SELECT DISTINCT T1.cust_name, T1.credit_score FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id


Question: Find the the name of the customers who have a loan with amount more than 3000.

SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE amount > 3000


Question: Find the city and name of bank branches that provide business loans.

Context: CREATE TABLE bank (bname VARCHAR, city VARCHAR, branch_id VARCHAR); CREATE TABLE loan (branch_id VARCHAR, loan_type VARCHAR)

SELECT T1.bname, T1.city FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T2.loan_type = 'Business'


Question: Find the names of bank branches that have provided a loan to any customer whose credit score is below 100.

Context: CREATE TABLE bank (bname VARCHAR, branch_id VARCHAR); CREATE TABLE customer (cust_id VARCHAR, credit_score INTEGER); CREATE TABLE loan (branch_id VARCHAR, cust_id VARCHAR)

SELECT T2.bname FROM loan AS T1 JOIN bank AS T2 ON T1.branch_id = T2.branch_id JOIN customer AS T3 ON T1.cust_id = T3.cust_id WHERE T3.credit_score < 100


Question: Find the total amount of loans provided by bank branches in the state of New York.

Context: CREATE TABLE bank (branch_id VARCHAR, state VARCHAR); CREATE TABLE loan (amount INTEGER, branch_id VARCHAR)

SELECT SUM(T2.amount) FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T1.state = 'New York'


Question: Find the average credit score of the customers who have some loan.

Context: CREATE TABLE loan (credit_score INTEGER, cust_id VARCHAR); CREATE TABLE customer (credit_score INTEGER, cust_id VARCHAR)

SELECT AVG(credit_score) FROM customer WHERE cust_id IN (SELECT cust_id FROM loan)


Question: Find the average credit score of the customers who do not have any loan.

SELECT AVG(credit_score) FROM customer WHERE NOT cust_id IN (SELECT cust_id FROM loan)


Question: How many assessment notes are there in total?

Context: CREATE TABLE ASSESSMENT_NOTES (Id VARCHAR)


Question: What are the dates of the assessment notes?

Context: CREATE TABLE Assessment_Notes (date_of_notes VARCHAR)

SELECT date_of_notes FROM Assessment_Notes


Question: How many addresses have zip code 197?

Context: CREATE TABLE ADDRESSES (zip_postcode VARCHAR)

SELECT COUNT(*) FROM ADDRESSES WHERE zip_postcode = "197"


Question: How many distinct incident type codes are there?

Context: CREATE TABLE Behavior_Incident (incident_type_code VARCHAR)

SELECT COUNT(DISTINCT incident_type_code) FROM Behavior_Incident


Question: Return all distinct detention type codes.

Context: CREATE TABLE Detention (detention_type_code VARCHAR)

SELECT DISTINCT detention_type_code FROM Detention


Question: What are the start and end dates for incidents with incident type code "NOISE"?

Context: CREATE TABLE Behavior_Incident (date_incident_start VARCHAR, date_incident_end VARCHAR, incident_type_code VARCHAR)

SELECT date_incident_start, date_incident_end FROM Behavior_Incident WHERE incident_type_code = "NOISE"


Question: Return all detention summaries.

Context: CREATE TABLE Detention (detention_summary VARCHAR)


Question: Return the cell phone number and email address for all students.

Context: CREATE TABLE STUDENTS (cell_mobile_number VARCHAR, email_address VARCHAR)

SELECT cell_mobile_number, email_address FROM STUDENTS


Question: What is the email of the student with first name "Emma" and last name "Rohan"?

Context: CREATE TABLE Students (email_address VARCHAR, first_name VARCHAR, last_name VARCHAR)

SELECT email_address FROM Students WHERE first_name = "Emma" AND last_name = "Rohan"


Question: How many distinct students have been in detention?

Context: CREATE TABLE Students_in_Detention (student_id VARCHAR)

SELECT COUNT(DISTINCT student_id) FROM Students_in_Detention


Question: What is the gender of the teacher with last name "Medhurst"?

Context: CREATE TABLE TEACHERS (gender VARCHAR, last_name VARCHAR)

SELECT gender FROM TEACHERS WHERE last_name = "Medhurst"


Question: What is the incident type description for the incident type with code "VIOLENCE"?

Context: CREATE TABLE Ref_Incident_Type (incident_type_description VARCHAR, incident_type_code VARCHAR)

SELECT incident_type_description FROM Ref_Incident_Type WHERE incident_type_code = "VIOLENCE"


Question: Find the maximum and minimum monthly rental for all student addresses.

Context: CREATE TABLE Student_Addresses (monthly_rental INTEGER)

SELECT MAX(monthly_rental), MIN(monthly_rental) FROM Student_Addresses


Question: Find the first names of teachers whose email address contains the word "man".

Context: CREATE TABLE Teachers (first_name VARCHAR, email_address VARCHAR)

SELECT first_name FROM Teachers WHERE email_address LIKE '%man%'


Question: List all information about the assessment notes sorted by date in ascending order.

SELECT * FROM Assessment_Notes ORDER BY date_of_notes


Question: List all cities of addresses in alphabetical order.

Context: CREATE TABLE Addresses (city VARCHAR)

SELECT city FROM Addresses ORDER BY city


Question: Find the first names and last names of teachers in alphabetical order of last name.

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

SELECT first_name, last_name FROM Teachers ORDER BY last_name


Question: Find all information about student addresses, and sort by monthly rental in descending order.

Context: CREATE TABLE Student_Addresses (monthly_rental VARCHAR)

SELECT * FROM Student_Addresses ORDER BY monthly_rental DESC


Question: Find the id and first name of the student that has the most number of assessment notes?

Context: CREATE TABLE Students (first_name VARCHAR, student_id VARCHAR); CREATE TABLE Assessment_Notes (student_id VARCHAR)

SELECT T1.student_id, T2.first_name FROM Assessment_Notes AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Find the ids and first names of the 3 teachers that have the most number of assessment notes?

Context: CREATE TABLE Assessment_Notes (teacher_id VARCHAR); CREATE TABLE Teachers (first_name VARCHAR, teacher_id VARCHAR)

SELECT T1.teacher_id, T2.first_name FROM Assessment_Notes AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id GROUP BY T1.teacher_id ORDER BY COUNT(*) DESC LIMIT 3


Question: Find the id and last name of the student that has the most behavior incidents?

Context: CREATE TABLE Students (last_name VARCHAR, student_id VARCHAR); CREATE TABLE Behavior_Incident (student_id VARCHAR)

SELECT T1.student_id, T2.last_name FROM Behavior_Incident AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY COUNT(*) DESC LIMIT 1


Question: Find the id and last name of the teacher that has the most detentions with detention type code "AFTER"?

Context: CREATE TABLE Detention (teacher_id VARCHAR, detention_type_code VARCHAR); CREATE TABLE Teachers (last_name VARCHAR, teacher_id VARCHAR)

SELECT T1.teacher_id, T2.last_name FROM Detention AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id WHERE T1.detention_type_code = "AFTER" GROUP BY T1.teacher_id ORDER BY COUNT(*) DESC LIMIT 1


Question: What are the id and first name of the student whose addresses have the highest average monthly rental?

Context: CREATE TABLE Students (first_name VARCHAR, student_id VARCHAR); CREATE TABLE Student_Addresses (student_id VARCHAR)

SELECT T1.student_id, T2.first_name FROM Student_Addresses AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY AVG(monthly_rental) DESC LIMIT 1