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)

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


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)

Answer: [SQL] SELECT state_province_county FROM addresses WHERE NOT address_id IN (SELECT employee_address_id FROM Employees) [/SQL]


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)

Answer: [SQL] SELECT customer_name, customer_phone, customer_email FROM Customers ORDER BY date_became_customer [/SQL]


Question: Find the name of the first 5 customers.

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

Answer: [SQL] SELECT customer_name FROM Customers ORDER BY date_became_customer LIMIT 5 [/SQL]


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

Context: CREATE TABLE Customers (payment_method VARCHAR)

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


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

Context: CREATE TABLE Delivery_Routes (route_name VARCHAR)

Answer: [SQL] SELECT route_name FROM Delivery_Routes ORDER BY route_name [/SQL]


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)

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


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)

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


Question: How many authors are there?

Context: CREATE TABLE authors (Id VARCHAR)

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


Question: How many institutions are there?

Context: CREATE TABLE inst (Id VARCHAR)

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


Question: How many papers are published in total?

Context: CREATE TABLE papers (Id VARCHAR)

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


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)

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


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

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


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)

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


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)

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


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

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


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)

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


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

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


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)

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


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)

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


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)

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


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

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


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

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


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

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


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

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


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

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


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)

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


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

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


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)

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


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)

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


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)

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


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

Context: CREATE TABLE papers (title VARCHAR)

Answer: [SQL] SELECT title FROM papers WHERE title LIKE "%ML%" [/SQL]


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

Context: CREATE TABLE papers (title VARCHAR)

Answer: [SQL] SELECT title FROM papers WHERE title LIKE "%Database%" [/SQL]


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)

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


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

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


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)

Answer: [SQL] SELECT t2.title FROM authorship AS t1 JOIN papers AS t2 ON t1.paperid = t2.paperid WHERE t1.authorder = (SELECT MAX(authorder) FROM authorship) [/SQL]


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

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

Answer: [SQL] SELECT fname FROM authors WHERE lname = "Ueno" [/SQL]


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

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

Answer: [SQL] SELECT lname FROM authors WHERE fname = "Amal" [/SQL]


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

Context: CREATE TABLE authors (fname VARCHAR)

Answer: [SQL] SELECT fname FROM authors ORDER BY fname [/SQL]


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

Context: CREATE TABLE authors (lname VARCHAR)

Answer: [SQL] SELECT lname FROM authors ORDER BY lname [/SQL]


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

Answer: [SQL] SELECT fname, lname FROM authors ORDER BY lname [/SQL]


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

Context: CREATE TABLE actor (last_name VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT last_name) FROM actor [/SQL]


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

Context: CREATE TABLE actor (first_name VARCHAR)

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


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

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

Answer: [SQL] SELECT first_name, last_name FROM actor GROUP BY first_name, last_name ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Which districts have at least two addresses?

Context: CREATE TABLE address (district VARCHAR)

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


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)

Answer: [SQL] SELECT phone, postal_code FROM address WHERE address = '1031 Daugavpils Parkway' [/SQL]


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)

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


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

Context: CREATE TABLE address (district VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM address WHERE district = 'California' [/SQL]


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)

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


Question: How many cities are in Australia?

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

Answer: [SQL] SELECT COUNT(*) FROM city AS T1 JOIN country AS T2 ON T1.country_id = T2.country_id WHERE T2.country = 'Australia' [/SQL]


Question: Which countries have at least 3 cities?

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

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


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)

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


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

Context: CREATE TABLE customer (active VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM customer WHERE active = '1' [/SQL]


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

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

Answer: [SQL] SELECT title, rental_rate FROM film ORDER BY rental_rate DESC LIMIT 1 [/SQL]


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)

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


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)

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


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

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


Question: Which store owns most items?

Context: CREATE TABLE inventory (store_id VARCHAR)

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


Question: What is the total amount of all payments?

Context: CREATE TABLE payment (amount INTEGER)

Answer: [SQL] SELECT SUM(amount) FROM payment [/SQL]


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)

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


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)

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


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)

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


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)

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


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)

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


Question: How many languages are in these films?

Context: CREATE TABLE film (language_id VARCHAR)

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


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

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

Answer: [SQL] SELECT title FROM film WHERE rating = 'R' [/SQL]


Question: Where is store 1 located?

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

Answer: [SQL] SELECT T2.address FROM store AS T1 JOIN address AS T2 ON T1.address_id = T2.address_id WHERE store_id = 1 [/SQL]


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)

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


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)

Answer: [SQL] SELECT T2.name FROM film AS T1 JOIN LANGUAGE AS T2 ON T1.language_id = T2.language_id WHERE T1.title = 'AIRPORT POLLOCK' [/SQL]


Question: How many stores are there?

Context: CREATE TABLE store (Id VARCHAR)

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


Question: How many kinds of different ratings are listed?

Context: CREATE TABLE film (rating VARCHAR)

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


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

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

Answer: [SQL] SELECT title FROM film WHERE special_features LIKE '%Deleted Scenes%' [/SQL]


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

Answer: [SQL] SELECT COUNT(*) FROM inventory WHERE store_id = 1 [/SQL]


Question: When did the first payment happen?

Context: CREATE TABLE payment (payment_date VARCHAR)

Answer: [SQL] SELECT payment_date FROM payment ORDER BY payment_date LIMIT 1 [/SQL]


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)

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


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)

Answer: [SQL] SELECT title FROM film WHERE LENGTH > 100 OR rating = 'PG' EXCEPT SELECT title FROM film WHERE replacement_cost > 200 [/SQL]


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)

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


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)

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


Question: Which store has most the customers?

Context: CREATE TABLE customer (store_id VARCHAR)

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


Question: What is the largest payment amount?

Context: CREATE TABLE payment (amount VARCHAR)

Answer: [SQL] SELECT amount FROM payment ORDER BY amount DESC LIMIT 1 [/SQL]


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)

Answer: [SQL] SELECT T2.address FROM staff AS T1 JOIN address AS T2 ON T1.address_id = T2.address_id WHERE T1.first_name = 'Elsa' [/SQL]


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)

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


Question: How many bank branches are there?

Context: CREATE TABLE bank (Id VARCHAR)

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


Question: How many customers are there?

Context: CREATE TABLE bank (no_of_customers INTEGER)

Answer: [SQL] SELECT SUM(no_of_customers) FROM bank [/SQL]


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

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

Answer: [SQL] SELECT SUM(no_of_customers) FROM bank WHERE city = 'New York City' [/SQL]


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

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

Answer: [SQL] SELECT AVG(no_of_customers) FROM bank WHERE state = 'Utah' [/SQL]


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

Answer: [SQL] SELECT AVG(no_of_customers) FROM bank [/SQL]


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

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

Answer: [SQL] SELECT city, state FROM bank WHERE bname = 'morningside' [/SQL]


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

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

Answer: [SQL] SELECT bname FROM bank WHERE state = 'New York' [/SQL]


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)

Answer: [SQL] SELECT cust_name FROM customer ORDER BY acc_bal [/SQL]


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)

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


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)

Answer: [SQL] SELECT state, acc_type, credit_score FROM customer WHERE no_of_loans = 0 [/SQL]


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

Context: CREATE TABLE bank (city VARCHAR)

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


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

Context: CREATE TABLE bank (state VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT state) FROM bank [/SQL]


Question: How many distinct types of accounts are there?

Context: CREATE TABLE customer (acc_type VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT acc_type) FROM customer [/SQL]


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

Answer: [SQL] SELECT cust_name, acc_bal FROM customer WHERE cust_name LIKE '%a%' [/SQL]


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

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

Answer: [SQL] SELECT SUM(acc_bal) FROM customer WHERE state = 'Utah' OR state = 'Texas' [/SQL]


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

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

Answer: [SQL] SELECT cust_name FROM customer WHERE acc_type = 'saving' INTERSECT SELECT cust_name FROM customer WHERE acc_type = 'checking' [/SQL]


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

Answer: [SQL] SELECT cust_name FROM customer EXCEPT SELECT cust_name FROM customer WHERE acc_type = 'saving' [/SQL]


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)

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


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)

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


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)

Answer: [SQL] SELECT cust_name FROM customer WHERE credit_score < (SELECT AVG(credit_score) FROM customer) [/SQL]


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)

Answer: [SQL] SELECT bname FROM bank ORDER BY no_of_customers DESC LIMIT 1 [/SQL]


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

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

Answer: [SQL] SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1 [/SQL]


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)

Answer: [SQL] SELECT cust_name, acc_type, acc_bal FROM customer ORDER BY credit_score DESC LIMIT 1 [/SQL]


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

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


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

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

Answer: [SQL] SELECT state FROM bank GROUP BY state ORDER BY SUM(no_of_customers) DESC LIMIT 1 [/SQL]


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)

Answer: [SQL] SELECT AVG(acc_bal), acc_type FROM customer WHERE credit_score < 50 GROUP BY acc_type [/SQL]


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)

Answer: [SQL] SELECT SUM(acc_bal), state FROM customer WHERE credit_score > 100 GROUP BY state [/SQL]


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)

Answer: [SQL] SELECT SUM(amount), T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname [/SQL]


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

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


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)

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


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)

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


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)

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


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

Answer: [SQL] SELECT DISTINCT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id [/SQL]


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)

Answer: [SQL] SELECT DISTINCT T1.cust_name, T1.credit_score FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id [/SQL]


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

Answer: [SQL] SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE amount > 3000 [/SQL]


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)

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


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)

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


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)

Answer: [SQL] SELECT SUM(T2.amount) FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T1.state = 'New York' [/SQL]


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)

Answer: [SQL] SELECT AVG(credit_score) FROM customer WHERE cust_id IN (SELECT cust_id FROM loan) [/SQL]


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

Answer: [SQL] SELECT AVG(credit_score) FROM customer WHERE NOT cust_id IN (SELECT cust_id FROM loan) [/SQL]


Question: How many assessment notes are there in total?

Context: CREATE TABLE ASSESSMENT_NOTES (Id VARCHAR)

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


Question: What are the dates of the assessment notes?

Context: CREATE TABLE Assessment_Notes (date_of_notes VARCHAR)

Answer: [SQL] SELECT date_of_notes FROM Assessment_Notes [/SQL]


Question: How many addresses have zip code 197?

Context: CREATE TABLE ADDRESSES (zip_postcode VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM ADDRESSES WHERE zip_postcode = "197" [/SQL]


Question: How many distinct incident type codes are there?

Context: CREATE TABLE Behavior_Incident (incident_type_code VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT incident_type_code) FROM Behavior_Incident [/SQL]


Question: Return all distinct detention type codes.

Context: CREATE TABLE Detention (detention_type_code VARCHAR)

Answer: [SQL] SELECT DISTINCT detention_type_code FROM Detention [/SQL]


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)

Answer: [SQL] SELECT date_incident_start, date_incident_end FROM Behavior_Incident WHERE incident_type_code = "NOISE" [/SQL]


Question: Return all detention summaries.

Context: CREATE TABLE Detention (detention_summary VARCHAR)

Answer: [SQL] SELECT detention_summary FROM Detention [/SQL]


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

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

Answer: [SQL] SELECT cell_mobile_number, email_address FROM STUDENTS [/SQL]


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)

Answer: [SQL] SELECT email_address FROM Students WHERE first_name = "Emma" AND last_name = "Rohan" [/SQL]


Question: How many distinct students have been in detention?

Context: CREATE TABLE Students_in_Detention (student_id VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT student_id) FROM Students_in_Detention [/SQL]


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

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

Answer: [SQL] SELECT gender FROM TEACHERS WHERE last_name = "Medhurst" [/SQL]


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)

Answer: [SQL] SELECT incident_type_description FROM Ref_Incident_Type WHERE incident_type_code = "VIOLENCE" [/SQL]


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

Context: CREATE TABLE Student_Addresses (monthly_rental INTEGER)

Answer: [SQL] SELECT MAX(monthly_rental), MIN(monthly_rental) FROM Student_Addresses [/SQL]


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

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

Answer: [SQL] SELECT first_name FROM Teachers WHERE email_address LIKE '%man%' [/SQL]


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

Answer: [SQL] SELECT * FROM Assessment_Notes ORDER BY date_of_notes [/SQL]


Question: List all cities of addresses in alphabetical order.

Context: CREATE TABLE Addresses (city VARCHAR)

Answer: [SQL] SELECT city FROM Addresses ORDER BY city [/SQL]


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)

Answer: [SQL] SELECT first_name, last_name FROM Teachers ORDER BY last_name [/SQL]


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

Context: CREATE TABLE Student_Addresses (monthly_rental VARCHAR)

Answer: [SQL] SELECT * FROM Student_Addresses ORDER BY monthly_rental DESC [/SQL]


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)

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


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)

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


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)

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


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)

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


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)

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


Question: Find the id and city of the student address with the highest average monthly rental.

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

Answer: [SQL] SELECT T2.address_id, T1.city FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id GROUP BY T2.address_id ORDER BY AVG(monthly_rental) DESC LIMIT 1 [/SQL]


Question: What are the code and description of the most frequent behavior incident type?

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

Answer: [SQL] SELECT T1.incident_type_code, T2.incident_type_description FROM Behavior_Incident AS T1 JOIN Ref_Incident_Type AS T2 ON T1.incident_type_code = T2.incident_type_code GROUP BY T1.incident_type_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What are the code and description of the least frequent detention type ?

Context: CREATE TABLE Ref_Detention_Type (detention_type_description VARCHAR, detention_type_code VARCHAR); CREATE TABLE Detention (detention_type_code VARCHAR)

Answer: [SQL] SELECT T1.detention_type_code, T2.detention_type_description FROM Detention AS T1 JOIN Ref_Detention_Type AS T2 ON T1.detention_type_code = T2.detention_type_code GROUP BY T1.detention_type_code ORDER BY COUNT(*) LIMIT 1 [/SQL]


Question: Find the dates of assessment notes for students with first name "Fanny".

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

Answer: [SQL] SELECT T1.date_of_notes FROM Assessment_Notes AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id WHERE T2.first_name = "Fanny" [/SQL]


Question: Find the texts of assessment notes for teachers with last name "Schuster".

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

Answer: [SQL] SELECT T1.text_of_notes FROM Assessment_Notes AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id WHERE T2.last_name = "Schuster" [/SQL]


Question: Find the start and end dates of behavior incidents of students with last name "Fahey".

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

Answer: [SQL] SELECT T1.date_incident_start, date_incident_end FROM Behavior_Incident AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id WHERE T2.last_name = "Fahey" [/SQL]


Question: Find the start and end dates of detentions of teachers with last name "Schultz".

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

Answer: [SQL] SELECT T1.datetime_detention_start, datetime_detention_end FROM Detention AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id WHERE T2.last_name = "Schultz" [/SQL]


Question: What are the id and zip code of the address with the highest monthly rental?

Context: CREATE TABLE Student_Addresses (address_id VARCHAR); CREATE TABLE Addresses (zip_postcode VARCHAR, address_id VARCHAR)

Answer: [SQL] SELECT T2.address_id, T1.zip_postcode FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id ORDER BY monthly_rental DESC LIMIT 1 [/SQL]


Question: What is the cell phone number of the student whose address has the lowest monthly rental?

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

Answer: [SQL] SELECT T2.cell_mobile_number FROM Student_Addresses AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id ORDER BY T1.monthly_rental LIMIT 1 [/SQL]


Question: What are the monthly rentals of student addresses in Texas state?

Context: CREATE TABLE Addresses (address_id VARCHAR, state_province_county VARCHAR); CREATE TABLE Student_Addresses (monthly_rental VARCHAR, address_id VARCHAR)

Answer: [SQL] SELECT T2.monthly_rental FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id WHERE T1.state_province_county = "Texas" [/SQL]


Question: What are the first names and last names of students with address in Wisconsin state?

Context: CREATE TABLE Addresses (address_id VARCHAR, state_province_county VARCHAR); CREATE TABLE Students (first_name VARCHAR, last_name VARCHAR, address_id VARCHAR)

Answer: [SQL] SELECT T2.first_name, T2.last_name FROM Addresses AS T1 JOIN Students AS T2 ON T1.address_id = T2.address_id WHERE T1.state_province_county = "Wisconsin" [/SQL]


Question: What are the line 1 and average monthly rentals of all student addresses?

Context: CREATE TABLE Addresses (line_1 VARCHAR, address_id VARCHAR); CREATE TABLE Student_Addresses (monthly_rental INTEGER, address_id VARCHAR)

Answer: [SQL] SELECT T1.line_1, AVG(T2.monthly_rental) FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id GROUP BY T2.address_id [/SQL]


Question: What is the zip code of the address where the teacher with first name "Lyla" lives?

Context: CREATE TABLE Teachers (address_id VARCHAR, first_name VARCHAR); CREATE TABLE Addresses (zip_postcode VARCHAR, address_id VARCHAR)

Answer: [SQL] SELECT T1.zip_postcode FROM Addresses AS T1 JOIN Teachers AS T2 ON T1.address_id = T2.address_id WHERE T2.first_name = "Lyla" [/SQL]


Question: What are the email addresses of teachers whose address has zip code "918"?

Context: CREATE TABLE Addresses (address_id VARCHAR, zip_postcode VARCHAR); CREATE TABLE Teachers (email_address VARCHAR, address_id VARCHAR)

Answer: [SQL] SELECT T2.email_address FROM Addresses AS T1 JOIN Teachers AS T2 ON T1.address_id = T2.address_id WHERE T1.zip_postcode = "918" [/SQL]


Question: How many students are not involved in any behavior incident?

Context: CREATE TABLE STUDENTS (student_id VARCHAR); CREATE TABLE Behavior_Incident (student_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM STUDENTS WHERE NOT student_id IN (SELECT student_id FROM Behavior_Incident) [/SQL]


Question: Find the last names of teachers who are not involved in any detention.

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

Answer: [SQL] SELECT last_name FROM Teachers EXCEPT SELECT T1.last_name FROM Teachers AS T1 JOIN Detention AS T2 ON T1.teacher_id = T2.teacher_id [/SQL]


Question: What are the line 1 of addresses shared by some students and some teachers?

Context: CREATE TABLE Teachers (address_id VARCHAR); CREATE TABLE Students (address_id VARCHAR); CREATE TABLE Addresses (line_1 VARCHAR, address_id VARCHAR)

Answer: [SQL] SELECT T1.line_1 FROM Addresses AS T1 JOIN Students AS T2 ON T1.address_id = T2.address_id INTERSECT SELECT T1.line_1 FROM Addresses AS T1 JOIN Teachers AS T2 ON T1.address_id = T2.address_id [/SQL]


Question: Which assets have 2 parts and have less than 2 fault logs? List the asset id and detail.

Context: CREATE TABLE Assets (asset_id VARCHAR, asset_details VARCHAR); CREATE TABLE Asset_Parts (asset_id VARCHAR); CREATE TABLE Fault_Log (asset_id VARCHAR)

Answer: [SQL] SELECT T1.asset_id, T1.asset_details FROM Assets AS T1 JOIN Asset_Parts AS T2 ON T1.asset_id = T2.asset_id GROUP BY T1.asset_id HAVING COUNT(*) = 2 INTERSECT SELECT T1.asset_id, T1.asset_details FROM Assets AS T1 JOIN Fault_Log AS T2 ON T1.asset_id = T2.asset_id GROUP BY T1.asset_id HAVING COUNT(*) < 2 [/SQL]


Question: How many assets does each maintenance contract contain? List the number and the contract id.

Context: CREATE TABLE Assets (maintenance_contract_id VARCHAR); CREATE TABLE Maintenance_Contracts (maintenance_contract_id VARCHAR)

Answer: [SQL] SELECT COUNT(*), T1.maintenance_contract_id FROM Maintenance_Contracts AS T1 JOIN Assets AS T2 ON T1.maintenance_contract_id = T2.maintenance_contract_id GROUP BY T1.maintenance_contract_id [/SQL]


Question: How many assets does each third party company supply? List the count and the company id.

Context: CREATE TABLE Assets (supplier_company_id VARCHAR); CREATE TABLE Third_Party_Companies (company_id VARCHAR)

Answer: [SQL] SELECT COUNT(*), T1.company_id FROM Third_Party_Companies AS T1 JOIN Assets AS T2 ON T1.company_id = T2.supplier_company_id GROUP BY T1.company_id [/SQL]


Question: Which third party companies have at least 2 maintenance engineers or have at least 2 maintenance contracts? List the company id and name.

Context: CREATE TABLE Maintenance_Contracts (maintenance_contract_company_id VARCHAR); CREATE TABLE Maintenance_Engineers (company_id VARCHAR); CREATE TABLE Third_Party_Companies (company_id VARCHAR, company_name VARCHAR)

Answer: [SQL] SELECT T1.company_id, T1.company_name FROM Third_Party_Companies AS T1 JOIN Maintenance_Engineers AS T2 ON T1.company_id = T2.company_id GROUP BY T1.company_id HAVING COUNT(*) >= 2 UNION SELECT T3.company_id, T3.company_name FROM Third_Party_Companies AS T3 JOIN Maintenance_Contracts AS T4 ON T3.company_id = T4.maintenance_contract_company_id GROUP BY T3.company_id HAVING COUNT(*) >= 2 [/SQL]


Question: What is the name and id of the staff who recorded the fault log but has not contacted any visiting engineers?

Context: CREATE TABLE Engineer_Visits (contact_staff_id VARCHAR); CREATE TABLE Staff (staff_name VARCHAR, staff_id VARCHAR); CREATE TABLE Fault_Log (recorded_by_staff_id VARCHAR)

Answer: [SQL] SELECT T1.staff_name, T1.staff_id FROM Staff AS T1 JOIN Fault_Log AS T2 ON T1.staff_id = T2.recorded_by_staff_id EXCEPT SELECT T3.staff_name, T3.staff_id FROM Staff AS T3 JOIN Engineer_Visits AS T4 ON T3.staff_id = T4.contact_staff_id [/SQL]


Question: Which engineer has visited the most times? Show the engineer id, first name and last name.

Context: CREATE TABLE Maintenance_Engineers (engineer_id VARCHAR, first_name VARCHAR, last_name VARCHAR); CREATE TABLE Engineer_Visits (Id VARCHAR)

Answer: [SQL] SELECT T1.engineer_id, T1.first_name, T1.last_name FROM Maintenance_Engineers AS T1 JOIN Engineer_Visits AS T2 GROUP BY T1.engineer_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Which parts have more than 2 faults? Show the part name and id.

Context: CREATE TABLE Parts (part_name VARCHAR, part_id VARCHAR); CREATE TABLE Part_Faults (part_id VARCHAR)

Answer: [SQL] SELECT T1.part_name, T1.part_id FROM Parts AS T1 JOIN Part_Faults AS T2 ON T1.part_id = T2.part_id GROUP BY T1.part_id HAVING COUNT(*) > 2 [/SQL]


Question: List all every engineer's first name, last name, details and coresponding skill description.

Context: CREATE TABLE Maintenance_Engineers (first_name VARCHAR, last_name VARCHAR, other_details VARCHAR, engineer_id VARCHAR); CREATE TABLE Engineer_Skills (engineer_id VARCHAR, skill_id VARCHAR); CREATE TABLE Skills (skill_description VARCHAR, skill_id VARCHAR)

Answer: [SQL] SELECT T1.first_name, T1.last_name, T1.other_details, T3.skill_description FROM Maintenance_Engineers AS T1 JOIN Engineer_Skills AS T2 ON T1.engineer_id = T2.engineer_id JOIN Skills AS T3 ON T2.skill_id = T3.skill_id [/SQL]


Question: For all the faults of different parts, what are all the decriptions of the skills required to fix them? List the name of the faults and the skill description.

Context: CREATE TABLE Skills_Required_To_Fix (part_fault_id VARCHAR, skill_id VARCHAR); CREATE TABLE Part_Faults (fault_short_name VARCHAR, part_fault_id VARCHAR); CREATE TABLE Skills (skill_description VARCHAR, skill_id VARCHAR)

Answer: [SQL] SELECT T1.fault_short_name, T3.skill_description FROM Part_Faults AS T1 JOIN Skills_Required_To_Fix AS T2 ON T1.part_fault_id = T2.part_fault_id JOIN Skills AS T3 ON T2.skill_id = T3.skill_id [/SQL]


Question: How many assets can each parts be used in? List the part name and the number.

Context: CREATE TABLE Parts (part_name VARCHAR, part_id VARCHAR); CREATE TABLE Asset_Parts (part_id VARCHAR)

Answer: [SQL] SELECT T1.part_name, COUNT(*) FROM Parts AS T1 JOIN Asset_Parts AS T2 ON T1.part_id = T2.part_id GROUP BY T1.part_name [/SQL]


Question: What are all the fault descriptions and the fault status of all the faults recoreded in the logs?

Context: CREATE TABLE Fault_Log (fault_description VARCHAR, fault_log_entry_id VARCHAR); CREATE TABLE Fault_Log_Parts (fault_status VARCHAR, fault_log_entry_id VARCHAR)

Answer: [SQL] SELECT T1.fault_description, T2.fault_status FROM Fault_Log AS T1 JOIN Fault_Log_Parts AS T2 ON T1.fault_log_entry_id = T2.fault_log_entry_id [/SQL]


Question: How many engineer visits are required at most for a single fault log? List the number and the log entry id.

Context: CREATE TABLE Fault_Log (fault_log_entry_id VARCHAR); CREATE TABLE Engineer_Visits (fault_log_entry_id VARCHAR)

Answer: [SQL] SELECT COUNT(*), T1.fault_log_entry_id FROM Fault_Log AS T1 JOIN Engineer_Visits AS T2 ON T1.fault_log_entry_id = T2.fault_log_entry_id GROUP BY T1.fault_log_entry_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What are all the distinct last names of all the engineers?

Context: CREATE TABLE Maintenance_Engineers (last_name VARCHAR)

Answer: [SQL] SELECT DISTINCT last_name FROM Maintenance_Engineers [/SQL]


Question: How many fault status codes are recorded in the fault log parts table?

Context: CREATE TABLE Fault_Log_Parts (fault_status VARCHAR)

Answer: [SQL] SELECT DISTINCT fault_status FROM Fault_Log_Parts [/SQL]


Question: Which engineers have never visited to maintain the assets? List the engineer first name and last name.

Context: CREATE TABLE Engineer_Visits (first_name VARCHAR, last_name VARCHAR, engineer_id VARCHAR); CREATE TABLE Maintenance_Engineers (first_name VARCHAR, last_name VARCHAR, engineer_id VARCHAR)

Answer: [SQL] SELECT first_name, last_name FROM Maintenance_Engineers WHERE NOT engineer_id IN (SELECT engineer_id FROM Engineer_Visits) [/SQL]


Question: List the asset id, details, make and model for every asset.

Context: CREATE TABLE Assets (asset_id VARCHAR, asset_details VARCHAR, asset_make VARCHAR, asset_model VARCHAR)

Answer: [SQL] SELECT asset_id, asset_details, asset_make, asset_model FROM Assets [/SQL]


Question: When was the first asset acquired?

Context: CREATE TABLE Assets (asset_acquired_date VARCHAR)

Answer: [SQL] SELECT asset_acquired_date FROM Assets ORDER BY asset_acquired_date LIMIT 1 [/SQL]


Question: Which part fault requires the most number of skills to fix? List part id and name.

Context: CREATE TABLE Part_Faults (part_id VARCHAR, part_fault_id VARCHAR); CREATE TABLE Skills_Required_To_Fix (part_fault_id VARCHAR); CREATE TABLE Parts (part_id VARCHAR, part_name VARCHAR)

Answer: [SQL] SELECT T1.part_id, T1.part_name FROM Parts AS T1 JOIN Part_Faults AS T2 ON T1.part_id = T2.part_id JOIN Skills_Required_To_Fix AS T3 ON T2.part_fault_id = T3.part_fault_id GROUP BY T1.part_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Which kind of part has the least number of faults? List the part name.

Answer: [SQL] SELECT T1.part_name FROM Parts AS T1 JOIN Part_Faults AS T2 ON T1.part_id = T2.part_id GROUP BY T1.part_name ORDER BY COUNT(*) LIMIT 1 [/SQL]


Question: Among those engineers who have visited, which engineer makes the least number of visits? List the engineer id, first name and last name.

Context: CREATE TABLE Engineer_Visits (engineer_id VARCHAR); CREATE TABLE Maintenance_Engineers (engineer_id VARCHAR, first_name VARCHAR, last_name VARCHAR)

Answer: [SQL] SELECT T1.engineer_id, T1.first_name, T1.last_name FROM Maintenance_Engineers AS T1 JOIN Engineer_Visits AS T2 ON T1.engineer_id = T2.engineer_id GROUP BY T1.engineer_id ORDER BY COUNT(*) LIMIT 1 [/SQL]


Question: Which staff have contacted which engineers? List the staff name and the engineer first name and last name.

Context: CREATE TABLE Engineer_Visits (contact_staff_id VARCHAR, engineer_id VARCHAR); CREATE TABLE Staff (staff_name VARCHAR, staff_id VARCHAR); CREATE TABLE Maintenance_Engineers (first_name VARCHAR, last_name VARCHAR, engineer_id VARCHAR)

Answer: [SQL] SELECT T1.staff_name, T3.first_name, T3.last_name FROM Staff AS T1 JOIN Engineer_Visits AS T2 ON T1.staff_id = T2.contact_staff_id JOIN Maintenance_Engineers AS T3 ON T2.engineer_id = T3.engineer_id [/SQL]


Question: Which fault log included the most number of faulty parts? List the fault log id, description and record time.

Context: CREATE TABLE Fault_Log (fault_log_entry_id VARCHAR, fault_description VARCHAR, fault_log_entry_datetime VARCHAR); CREATE TABLE Fault_Log_Parts (fault_log_entry_id VARCHAR)

Answer: [SQL] SELECT T1.fault_log_entry_id, T1.fault_description, T1.fault_log_entry_datetime FROM Fault_Log AS T1 JOIN Fault_Log_Parts AS T2 ON T1.fault_log_entry_id = T2.fault_log_entry_id GROUP BY T1.fault_log_entry_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Which skill is used in fixing the most number of faults? List the skill id and description.

Context: CREATE TABLE Skills (skill_id VARCHAR, skill_description VARCHAR); CREATE TABLE Skills_Required_To_Fix (skill_id VARCHAR)

Answer: [SQL] SELECT T1.skill_id, T1.skill_description FROM Skills AS T1 JOIN Skills_Required_To_Fix AS T2 ON T1.skill_id = T2.skill_id GROUP BY T1.skill_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What are all the distinct asset models?

Context: CREATE TABLE Assets (asset_model VARCHAR)

Answer: [SQL] SELECT DISTINCT asset_model FROM Assets [/SQL]


Question: List the all the assets make, model, details by the disposed date ascendingly.

Context: CREATE TABLE Assets (asset_make VARCHAR, asset_model VARCHAR, asset_details VARCHAR, asset_disposed_date VARCHAR)

Answer: [SQL] SELECT asset_make, asset_model, asset_details FROM Assets ORDER BY asset_disposed_date [/SQL]


Question: Which part has the least chargeable amount? List the part id and amount.

Context: CREATE TABLE Parts (part_id VARCHAR, chargeable_amount VARCHAR)

Answer: [SQL] SELECT part_id, chargeable_amount FROM Parts ORDER BY chargeable_amount LIMIT 1 [/SQL]


Question: Which company started the earliest the maintenance contract? Show the company name.

Context: CREATE TABLE Third_Party_Companies (company_name VARCHAR, company_id VARCHAR); CREATE TABLE Maintenance_Contracts (maintenance_contract_company_id VARCHAR, contract_start_date VARCHAR)

Answer: [SQL] SELECT T1.company_name FROM Third_Party_Companies AS T1 JOIN Maintenance_Contracts AS T2 ON T1.company_id = T2.maintenance_contract_company_id ORDER BY T2.contract_start_date LIMIT 1 [/SQL]


Question: What is the description of the type of the company who concluded its contracts most recently?

Context: CREATE TABLE Maintenance_Contracts (maintenance_contract_company_id VARCHAR, contract_end_date VARCHAR); CREATE TABLE Third_Party_Companies (company_name VARCHAR, company_id VARCHAR, company_type_code VARCHAR); CREATE TABLE Ref_Company_Types (company_type_code VARCHAR)

Answer: [SQL] SELECT T1.company_name FROM Third_Party_Companies AS T1 JOIN Maintenance_Contracts AS T2 ON T1.company_id = T2.maintenance_contract_company_id JOIN Ref_Company_Types AS T3 ON T1.company_type_code = T3.company_type_code ORDER BY T2.contract_end_date DESC LIMIT 1 [/SQL]


Question: Which gender makes up the majority of the staff?

Context: CREATE TABLE staff (gender VARCHAR)

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


Question: How many engineers did each staff contact? List both the contact staff name and number of engineers contacted.

Context: CREATE TABLE Engineer_Visits (contact_staff_id VARCHAR); CREATE TABLE Staff (staff_name VARCHAR, staff_id VARCHAR)

Answer: [SQL] SELECT T1.staff_name, COUNT(*) FROM Staff AS T1 JOIN Engineer_Visits AS T2 ON T1.staff_id = T2.contact_staff_id GROUP BY T1.staff_name [/SQL]


Question: Which assets did not incur any fault log? List the asset model.

Context: CREATE TABLE Fault_Log (asset_model VARCHAR, asset_id VARCHAR); CREATE TABLE Assets (asset_model VARCHAR, asset_id VARCHAR)

Answer: [SQL] SELECT asset_model FROM Assets WHERE NOT asset_id IN (SELECT asset_id FROM Fault_Log) [/SQL]


Question: list the local authorities and services provided by all stations.

Context: CREATE TABLE station (local_authority VARCHAR, services VARCHAR)

Answer: [SQL] SELECT local_authority, services FROM station [/SQL]


Question: show all train numbers and names ordered by their time from early to late.

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

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


Question: Give me the times and numbers of all trains that go to Chennai, ordered by time.

Context: CREATE TABLE train (TIME VARCHAR, train_number VARCHAR, destination VARCHAR)

Answer: [SQL] SELECT TIME, train_number FROM train WHERE destination = 'Chennai' ORDER BY TIME [/SQL]


Question: How many trains have 'Express' in their names?

Context: CREATE TABLE train (name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM train WHERE name LIKE "%Express%" [/SQL]


Question: Find the number and time of the train that goes from Chennai to Guruvayur.

Context: CREATE TABLE train (train_number VARCHAR, TIME VARCHAR, origin VARCHAR, destination VARCHAR)

Answer: [SQL] SELECT train_number, TIME FROM train WHERE origin = 'Chennai' AND destination = 'Guruvayur' [/SQL]


Question: Find the number of trains starting from each origin.

Context: CREATE TABLE train (origin VARCHAR)

Answer: [SQL] SELECT origin, COUNT(*) FROM train GROUP BY origin [/SQL]


Question: Find the name of the train whose route runs through greatest number of stations.

Context: CREATE TABLE route (train_id VARCHAR); CREATE TABLE train (name VARCHAR, id VARCHAR)

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


Question: Find the number of trains for each station, as well as the station network name and services.

Context: CREATE TABLE route (station_id VARCHAR); CREATE TABLE station (network_name VARCHAR, services VARCHAR, id VARCHAR)

Answer: [SQL] SELECT COUNT(*), t1.network_name, t1.services FROM station AS t1 JOIN route AS t2 ON t1.id = t2.station_id GROUP BY t2.station_id [/SQL]


Question: What is the average high temperature for each day of week?

Context: CREATE TABLE weekly_weather (day_of_week VARCHAR, high_temperature INTEGER)

Answer: [SQL] SELECT AVG(high_temperature), day_of_week FROM weekly_weather GROUP BY day_of_week [/SQL]


Question: Give me the maximum low temperature and average precipitation at the Amersham station.

Context: CREATE TABLE weekly_weather (low_temperature INTEGER, precipitation INTEGER, station_id VARCHAR); CREATE TABLE station (id VARCHAR, network_name VARCHAR)

Answer: [SQL] SELECT MAX(t1.low_temperature), AVG(t1.precipitation) FROM weekly_weather AS t1 JOIN station AS t2 ON t1.station_id = t2.id WHERE t2.network_name = "Amersham" [/SQL]


Question: Find names and times of trains that run through stations for the local authority Chiltern.

Context: CREATE TABLE station (id VARCHAR, local_authority VARCHAR); CREATE TABLE route (station_id VARCHAR, train_id VARCHAR); CREATE TABLE train (name VARCHAR, time VARCHAR, id VARCHAR)

Answer: [SQL] SELECT t3.name, t3.time FROM station AS t1 JOIN route AS t2 ON t1.id = t2.station_id JOIN train AS t3 ON t2.train_id = t3.id WHERE t1.local_authority = "Chiltern" [/SQL]


Question: How many different services are provided by all stations?

Context: CREATE TABLE station (services VARCHAR)

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


Question: Find the id and local authority of the station with has the highest average high temperature.

Context: CREATE TABLE weekly_weather (station_id VARCHAR); CREATE TABLE station (id VARCHAR, local_authority VARCHAR)

Answer: [SQL] SELECT t2.id, t2.local_authority FROM weekly_weather AS t1 JOIN station AS t2 ON t1.station_id = t2.id GROUP BY t1.station_id ORDER BY AVG(high_temperature) DESC LIMIT 1 [/SQL]


Question: Find the id and local authority of the station whose maximum precipitation is higher than 50.

Context: CREATE TABLE weekly_weather (station_id VARCHAR, precipitation INTEGER); CREATE TABLE station (id VARCHAR, local_authority VARCHAR)

Answer: [SQL] SELECT t2.id, t2.local_authority FROM weekly_weather AS t1 JOIN station AS t2 ON t1.station_id = t2.id GROUP BY t1.station_id HAVING MAX(t1.precipitation) > 50 [/SQL]


Question: show the lowest low temperature and highest wind speed in miles per hour.

Context: CREATE TABLE weekly_weather (low_temperature INTEGER, wind_speed_mph INTEGER)

Answer: [SQL] SELECT MIN(low_temperature), MAX(wind_speed_mph) FROM weekly_weather [/SQL]


Question: Find the origins from which more than 1 train starts.

Context: CREATE TABLE train (origin VARCHAR)

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


Question: Find the number of professors in accounting department.

Context: CREATE TABLE professor (dept_code VARCHAR); CREATE TABLE department (dept_code VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM professor AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code WHERE DEPT_NAME = "Accounting" [/SQL]


Question: How many professors are teaching class with code ACCT-211?

Context: CREATE TABLE CLASS (PROF_NUM VARCHAR, CRS_CODE VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT PROF_NUM) FROM CLASS WHERE CRS_CODE = "ACCT-211" [/SQL]


Question: What is the first and last name of the professor in biology department?

Context: CREATE TABLE professor (dept_code VARCHAR, EMP_NUM VARCHAR); CREATE TABLE department (dept_code VARCHAR); CREATE TABLE employee (EMP_FNAME VARCHAR, EMP_LNAME VARCHAR, EMP_NUM VARCHAR)

Answer: [SQL] SELECT T3.EMP_FNAME, T3.EMP_LNAME FROM professor AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code JOIN employee AS T3 ON T1.EMP_NUM = T3.EMP_NUM WHERE DEPT_NAME = "Biology" [/SQL]


Question: What are the first names and date of birth of professors teaching course ACCT-211?

Context: CREATE TABLE CLASS (PROF_NUM VARCHAR); CREATE TABLE employee (EMP_FNAME VARCHAR, EMP_DOB VARCHAR, EMP_NUM VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.EMP_FNAME, T1.EMP_DOB FROM employee AS T1 JOIN CLASS AS T2 ON T1.EMP_NUM = T2.PROF_NUM WHERE CRS_CODE = "ACCT-211" [/SQL]


Question: How many classes are professor whose last name is Graztevski has?

Context: CREATE TABLE CLASS (PROF_NUM VARCHAR); CREATE TABLE employee (EMP_NUM VARCHAR, EMP_LNAME VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM employee AS T1 JOIN CLASS AS T2 ON T1.EMP_NUM = T2.PROF_NUM WHERE T1.EMP_LNAME = 'Graztevski' [/SQL]


Question: What is the code of the school where the accounting department belongs to?

Context: CREATE TABLE department (school_code VARCHAR, dept_name VARCHAR)

Answer: [SQL] SELECT school_code FROM department WHERE dept_name = "Accounting" [/SQL]


Question: How many credits does course CIS-220 have, and what its description?

Context: CREATE TABLE course (crs_credit VARCHAR, crs_description VARCHAR, crs_code VARCHAR)

Answer: [SQL] SELECT crs_credit, crs_description FROM course WHERE crs_code = 'CIS-220' [/SQL]


Question: what is the address of history department?

Context: CREATE TABLE department (dept_address VARCHAR, dept_name VARCHAR)

Answer: [SQL] SELECT dept_address FROM department WHERE dept_name = 'History' [/SQL]


Question: How many different locations does the school with code BUS has?

Context: CREATE TABLE department (dept_address VARCHAR, school_code VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT dept_address) FROM department WHERE school_code = 'BUS' [/SQL]


Question: How many different locations does each school have?

Context: CREATE TABLE department (school_code VARCHAR, dept_address VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT dept_address), school_code FROM department GROUP BY school_code [/SQL]


Question: Find the description and credit for the course QM-261?

Answer: [SQL] SELECT crs_credit, crs_description FROM course WHERE crs_code = 'QM-261' [/SQL]


Question: Find the number of departments in each school.

Answer: [SQL] SELECT COUNT(DISTINCT dept_name), school_code FROM department GROUP BY school_code [/SQL]


Question: Find the number of different departments in each school whose number of different departments is less than 5.

Answer: [SQL] SELECT COUNT(DISTINCT dept_name), school_code FROM department GROUP BY school_code HAVING COUNT(DISTINCT dept_name) < 5 [/SQL]


Question: How many sections does each course has?

Context: CREATE TABLE CLASS (crs_code VARCHAR)

Answer: [SQL] SELECT COUNT(*), crs_code FROM CLASS GROUP BY crs_code [/SQL]


Question: What is the total credit does each department offer?

Context: CREATE TABLE course (dept_code VARCHAR, crs_credit INTEGER)

Answer: [SQL] SELECT SUM(crs_credit), dept_code FROM course GROUP BY dept_code [/SQL]


Question: Find the number of classes offered for all class rooms that held at least 2 classes.

Context: CREATE TABLE CLASS (class_room VARCHAR)

Answer: [SQL] SELECT COUNT(*), class_room FROM CLASS GROUP BY class_room HAVING COUNT(*) >= 2 [/SQL]


Question: Find the number of classes in each department.

Context: CREATE TABLE CLASS (crs_code VARCHAR); CREATE TABLE course (crs_code VARCHAR)

Answer: [SQL] SELECT COUNT(*), dept_code FROM CLASS AS T1 JOIN course AS T2 ON T1.crs_code = T2.crs_code GROUP BY dept_code [/SQL]


Question: Find the number of classes in each school.

Context: CREATE TABLE department (school_code VARCHAR, dept_code VARCHAR); CREATE TABLE CLASS (crs_code VARCHAR); CREATE TABLE course (crs_code VARCHAR, dept_code VARCHAR)

Answer: [SQL] SELECT COUNT(*), T3.school_code FROM CLASS AS T1 JOIN course AS T2 ON T1.crs_code = T2.crs_code JOIN department AS T3 ON T2.dept_code = T3.dept_code GROUP BY T3.school_code [/SQL]


Question: What is the number of professors for different school?

Context: CREATE TABLE department (school_code VARCHAR, dept_code VARCHAR); CREATE TABLE professor (dept_code VARCHAR)

Answer: [SQL] SELECT COUNT(*), T1.school_code FROM department AS T1 JOIN professor AS T2 ON T1.dept_code = T2.dept_code GROUP BY T1.school_code [/SQL]


Question: Find the count and code of the job has most employees.

Context: CREATE TABLE employee (emp_jobcode VARCHAR)

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


Question: Which school has the smallest amount of professors?

Answer: [SQL] SELECT T1.school_code FROM department AS T1 JOIN professor AS T2 ON T1.dept_code = T2.dept_code GROUP BY T1.school_code ORDER BY COUNT(*) LIMIT 1 [/SQL]


Question: Find the number of professors with a Ph.D. degree in each department.

Context: CREATE TABLE professor (dept_code VARCHAR, prof_high_degree VARCHAR)

Answer: [SQL] SELECT COUNT(*), dept_code FROM professor WHERE prof_high_degree = 'Ph.D.' GROUP BY dept_code [/SQL]


Question: Find the number of students for each department.

Context: CREATE TABLE student (dept_code VARCHAR)

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


Question: Find the total number of hours have done for all students in each department.

Context: CREATE TABLE student (dept_code VARCHAR, stu_hrs INTEGER)

Answer: [SQL] SELECT SUM(stu_hrs), dept_code FROM student GROUP BY dept_code [/SQL]


Question: Find the max, average, and minimum gpa of all students in each department.

Context: CREATE TABLE student (dept_code VARCHAR, stu_gpa INTEGER)

Answer: [SQL] SELECT MAX(stu_gpa), AVG(stu_gpa), MIN(stu_gpa), dept_code FROM student GROUP BY dept_code [/SQL]


Question: What is the name and the average gpa of department whose students have the highest average gpa?

Context: CREATE TABLE department (dept_name VARCHAR, dept_code VARCHAR); CREATE TABLE student (stu_gpa INTEGER, dept_code VARCHAR)

Answer: [SQL] SELECT T2.dept_name, AVG(T1.stu_gpa) FROM student AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code GROUP BY T1.dept_code ORDER BY AVG(T1.stu_gpa) DESC LIMIT 1 [/SQL]


Question: how many schools exist in total?

Context: CREATE TABLE department (school_code VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT school_code) FROM department [/SQL]


Question: How many different classes are there?

Context: CREATE TABLE CLASS (class_code VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT class_code) FROM CLASS [/SQL]


Question: How many courses are offered?

Context: CREATE TABLE CLASS (crs_code VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT crs_code) FROM CLASS [/SQL]


Question: How many departments does the college has?

Context: CREATE TABLE department (dept_name VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT dept_name) FROM department [/SQL]


Question: How many courses are offered by the Computer Info. Systems department?

Context: CREATE TABLE course (dept_code VARCHAR); CREATE TABLE department (dept_code VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM department AS T1 JOIN course AS T2 ON T1.dept_code = T2.dept_code WHERE dept_name = "Computer Info. Systems" [/SQL]


Question: How many sections does course ACCT-211 has?

Context: CREATE TABLE CLASS (class_section VARCHAR, crs_code VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT class_section) FROM CLASS WHERE crs_code = 'ACCT-211' [/SQL]


Question: Find the total credits of all classes offered by each department.

Context: CREATE TABLE CLASS (crs_code VARCHAR); CREATE TABLE course (dept_code VARCHAR, crs_credit INTEGER, crs_code VARCHAR)

Answer: [SQL] SELECT SUM(T1.crs_credit), T1.dept_code FROM course AS T1 JOIN CLASS AS T2 ON T1.crs_code = T2.crs_code GROUP BY T1.dept_code [/SQL]


Question: Find the name of the department that offers the largest number of credits of all classes.

Context: CREATE TABLE CLASS (crs_code VARCHAR); CREATE TABLE department (dept_name VARCHAR, dept_code VARCHAR); CREATE TABLE course (dept_code VARCHAR, crs_code VARCHAR, crs_credit INTEGER)

Answer: [SQL] SELECT T3.dept_name FROM course AS T1 JOIN CLASS AS T2 ON T1.crs_code = T2.crs_code JOIN department AS T3 ON T1.dept_code = T3.dept_code GROUP BY T1.dept_code ORDER BY SUM(T1.crs_credit) DESC LIMIT 1 [/SQL]


Question: How many students enrolled in class ACCT-211?

Context: CREATE TABLE enroll (class_code VARCHAR); CREATE TABLE CLASS (class_code VARCHAR, crs_code VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM CLASS AS T1 JOIN enroll AS T2 ON T1.class_code = T2.class_code WHERE T1.crs_code = 'ACCT-211' [/SQL]


Question: What is the first name of each student enrolled in class ACCT-211?

Context: CREATE TABLE student (stu_fname VARCHAR, stu_num VARCHAR); CREATE TABLE CLASS (class_code VARCHAR, crs_code VARCHAR); CREATE TABLE enroll (class_code VARCHAR, stu_num VARCHAR)

Answer: [SQL] SELECT T3.stu_fname FROM CLASS AS T1 JOIN enroll AS T2 ON T1.class_code = T2.class_code JOIN student AS T3 ON T2.stu_num = T3.stu_num WHERE T1.crs_code = 'ACCT-211' [/SQL]


Question: What is the first name of students enrolled in class ACCT-211 and got grade C?

Context: CREATE TABLE CLASS (class_code VARCHAR, crs_code VARCHAR); CREATE TABLE student (stu_fname VARCHAR, stu_num VARCHAR); CREATE TABLE enroll (class_code VARCHAR, stu_num VARCHAR, enroll_grade VARCHAR)

Answer: [SQL] SELECT T3.stu_fname FROM CLASS AS T1 JOIN enroll AS T2 ON T1.class_code = T2.class_code JOIN student AS T3 ON T2.stu_num = T3.stu_num WHERE T1.crs_code = 'ACCT-211' AND T2.enroll_grade = 'C' [/SQL]


Question: Find the total number of employees.

Context: CREATE TABLE employee (Id VARCHAR)

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


Question: How many professors do have a Ph.D. degree?

Context: CREATE TABLE professor (prof_high_degree VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM professor WHERE prof_high_degree = 'Ph.D.' [/SQL]


Question: How many students are enrolled in the class taught by some professor from the accounting department?

Context: CREATE TABLE enroll (class_code VARCHAR); CREATE TABLE department (dept_code VARCHAR, dept_name VARCHAR); CREATE TABLE course (crs_code VARCHAR, dept_code VARCHAR); CREATE TABLE CLASS (class_code VARCHAR, crs_code VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM CLASS AS T1 JOIN enroll AS T2 ON T1.class_code = T2.class_code JOIN course AS T3 ON T1.crs_code = T3.crs_code JOIN department AS T4 ON T3.dept_code = T4.dept_code WHERE T4.dept_name = 'Accounting' [/SQL]


Question: What is the name of the department that has the largest number of students enrolled?

Context: CREATE TABLE enroll (class_code VARCHAR); CREATE TABLE CLASS (class_code VARCHAR, crs_code VARCHAR); CREATE TABLE course (dept_code VARCHAR, crs_code VARCHAR); CREATE TABLE department (dept_name VARCHAR, dept_code VARCHAR)

Answer: [SQL] SELECT T4.dept_name FROM CLASS AS T1 JOIN enroll AS T2 ON T1.class_code = T2.class_code JOIN course AS T3 ON T1.crs_code = T3.crs_code JOIN department AS T4 ON T3.dept_code = T4.dept_code GROUP BY T3.dept_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: list names of all departments ordered by their names.

Answer: [SQL] SELECT dept_name FROM department ORDER BY dept_name [/SQL]


Question: List the codes of all courses that take place in room KLR209.

Context: CREATE TABLE CLASS (class_code VARCHAR, class_room VARCHAR)

Answer: [SQL] SELECT class_code FROM CLASS WHERE class_room = 'KLR209' [/SQL]


Question: List the first name of all employees with job code PROF ordered by their date of birth.

Context: CREATE TABLE employee (emp_fname VARCHAR, emp_jobcode VARCHAR, emp_dob VARCHAR)

Answer: [SQL] SELECT emp_fname FROM employee WHERE emp_jobcode = 'PROF' ORDER BY emp_dob [/SQL]


Question: Find the first names and offices of all professors sorted by alphabetical order of their first name.

Context: CREATE TABLE professor (prof_office VARCHAR, emp_num VARCHAR); CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR)

Answer: [SQL] SELECT T2.emp_fname, T1.prof_office FROM professor AS T1 JOIN employee AS T2 ON T1.emp_num = T2.emp_num ORDER BY T2.emp_fname [/SQL]


Question: What is the first and last name of the oldest employee?

Context: CREATE TABLE employee (emp_fname VARCHAR, emp_lname VARCHAR, emp_dob VARCHAR)

Answer: [SQL] SELECT emp_fname, emp_lname FROM employee ORDER BY emp_dob LIMIT 1 [/SQL]


Question: What is the first, last name, gpa of the youngest one among students whose GPA is above 3?

Context: CREATE TABLE student (stu_fname VARCHAR, stu_lname VARCHAR, stu_gpa INTEGER, stu_dob VARCHAR)

Answer: [SQL] SELECT stu_fname, stu_lname, stu_gpa FROM student WHERE stu_gpa > 3 ORDER BY stu_dob DESC LIMIT 1 [/SQL]


Question: What is the first name of students who got grade C in any class?

Context: CREATE TABLE student (stu_num VARCHAR); CREATE TABLE enroll (stu_num VARCHAR)

Answer: [SQL] SELECT DISTINCT stu_fname FROM student AS T1 JOIN enroll AS T2 ON T1.stu_num = T2.stu_num WHERE enroll_grade = 'C' [/SQL]


Question: What is the name of department where has the smallest number of professors?

Context: CREATE TABLE professor (dept_code VARCHAR); CREATE TABLE department (dept_name VARCHAR, dept_code VARCHAR)

Answer: [SQL] SELECT T2.dept_name FROM professor AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code GROUP BY T1.dept_code ORDER BY COUNT(*) LIMIT 1 [/SQL]


Question: What is the name of department where has the largest number of professors with a Ph.D. degree?

Context: CREATE TABLE professor (dept_code VARCHAR, prof_high_degree VARCHAR); CREATE TABLE department (dept_name VARCHAR, dept_code VARCHAR)

Answer: [SQL] SELECT T2.dept_name, T1.dept_code FROM professor AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code WHERE T1.prof_high_degree = 'Ph.D.' GROUP BY T1.dept_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What are the first names of the professors who do not teach a class.

Context: CREATE TABLE employee (emp_fname VARCHAR, emp_jobcode VARCHAR); CREATE TABLE CLASS (prof_num VARCHAR); CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR)

Answer: [SQL] SELECT emp_fname FROM employee WHERE emp_jobcode = 'PROF' EXCEPT SELECT T1.emp_fname FROM employee AS T1 JOIN CLASS AS T2 ON T1.emp_num = T2.prof_num [/SQL]


Question: What is the first names of the professors from the history department who do not teach a class.

Context: CREATE TABLE professor (emp_num VARCHAR, dept_code VARCHAR); CREATE TABLE department (dept_code VARCHAR, dept_name VARCHAR); CREATE TABLE CLASS (prof_num VARCHAR); CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR)

Answer: [SQL] SELECT T1.emp_fname FROM employee AS T1 JOIN professor AS T2 ON T1.emp_num = T2.emp_num JOIN department AS T3 ON T2.dept_code = T3.dept_code WHERE T3.dept_name = 'History' EXCEPT SELECT T4.emp_fname FROM employee AS T4 JOIN CLASS AS T5 ON T4.emp_num = T5.prof_num [/SQL]


Question: What is the last name and office of the professor from the history department?

Context: CREATE TABLE department (dept_code VARCHAR, dept_name VARCHAR); CREATE TABLE employee (emp_lname VARCHAR, emp_num VARCHAR); CREATE TABLE professor (prof_office VARCHAR, emp_num VARCHAR, dept_code VARCHAR)

Answer: [SQL] SELECT T1.emp_lname, T2.prof_office FROM employee AS T1 JOIN professor AS T2 ON T1.emp_num = T2.emp_num JOIN department AS T3 ON T2.dept_code = T3.dept_code WHERE T3.dept_name = 'History' [/SQL]


Question: What is department name and office for the professor whose last name is Heffington?

Context: CREATE TABLE employee (emp_num VARCHAR, emp_lname VARCHAR); CREATE TABLE department (dept_name VARCHAR, dept_code VARCHAR); CREATE TABLE professor (prof_office VARCHAR, emp_num VARCHAR, dept_code VARCHAR)

Answer: [SQL] SELECT T3.dept_name, T2.prof_office FROM employee AS T1 JOIN professor AS T2 ON T1.emp_num = T2.emp_num JOIN department AS T3 ON T2.dept_code = T3.dept_code WHERE T1.emp_lname = 'Heffington' [/SQL]


Question: Find the last name and hire date of the professor who is in office DRE 102.

Context: CREATE TABLE professor (emp_num VARCHAR, prof_office VARCHAR); CREATE TABLE employee (emp_lname VARCHAR, emp_hiredate VARCHAR, emp_num VARCHAR)

Answer: [SQL] SELECT T1.emp_lname, T1.emp_hiredate FROM employee AS T1 JOIN professor AS T2 ON T1.emp_num = T2.emp_num WHERE T2.prof_office = 'DRE 102' [/SQL]


Question: What is the code of the course which the student whose last name is Smithson took?

Context: CREATE TABLE student (stu_num VARCHAR, stu_lname VARCHAR); CREATE TABLE enroll (class_code VARCHAR, stu_num VARCHAR); CREATE TABLE CLASS (crs_code VARCHAR, class_code VARCHAR)

Answer: [SQL] SELECT T1.crs_code FROM CLASS AS T1 JOIN enroll AS T2 ON T1.class_code = T2.class_code JOIN student AS T3 ON T3.stu_num = T2.stu_num WHERE T3.stu_lname = 'Smithson' [/SQL]


Question: What are the description and credit of the course which the student whose last name is Smithson took?

Context: CREATE TABLE student (stu_num VARCHAR, stu_lname VARCHAR); CREATE TABLE course (crs_description VARCHAR, crs_credit VARCHAR, crs_code VARCHAR); CREATE TABLE CLASS (class_code VARCHAR, crs_code VARCHAR); CREATE TABLE enroll (class_code VARCHAR, stu_num VARCHAR)

Answer: [SQL] SELECT T4.crs_description, T4.crs_credit FROM CLASS AS T1 JOIN enroll AS T2 ON T1.class_code = T2.class_code JOIN student AS T3 ON T3.stu_num = T2.stu_num JOIN course AS T4 ON T4.crs_code = T1.crs_code WHERE T3.stu_lname = 'Smithson' [/SQL]


Question: How many professors who has a either Ph.D. or MA degree?

Context: CREATE TABLE professor (prof_high_degree VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM professor WHERE prof_high_degree = 'Ph.D.' OR prof_high_degree = 'MA' [/SQL]


Question: How many professors who are from either Accounting or Biology department?

Context: CREATE TABLE department (dept_code VARCHAR, dept_name VARCHAR); CREATE TABLE professor (dept_code VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM professor AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code WHERE T2.dept_name = 'Accounting' OR T2.dept_name = 'Biology' [/SQL]


Question: Find the first name of the professor who is teaching two courses with code CIS-220 and QM-261.

Context: CREATE TABLE CLASS (prof_num VARCHAR); CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR)

Answer: [SQL] SELECT T1.emp_fname FROM employee AS T1 JOIN CLASS AS T2 ON T1.emp_num = T2.prof_num WHERE crs_code = 'CIS-220' INTERSECT SELECT T1.emp_fname FROM employee AS T1 JOIN CLASS AS T2 ON T1.emp_num = T2.prof_num WHERE crs_code = 'QM-261' [/SQL]


Question: Find the first name of student who is taking classes from accounting and Computer Info. Systems departments

Context: CREATE TABLE CLASS (class_code VARCHAR, crs_code VARCHAR); CREATE TABLE enroll (stu_num VARCHAR, class_code VARCHAR); CREATE TABLE department (dept_code VARCHAR, dept_name VARCHAR); CREATE TABLE course (crs_code VARCHAR, dept_code VARCHAR); CREATE TABLE student (stu_fname VARCHAR, stu_num VARCHAR)

Answer: [SQL] SELECT T1.stu_fname FROM student AS T1 JOIN enroll AS T2 ON T1.stu_num = T2.stu_num JOIN CLASS AS T3 ON T2.class_code = T3.class_code JOIN course AS T4 ON T3.crs_code = T4.crs_code JOIN department AS T5 ON T5.dept_code = T4.dept_code WHERE T5.dept_name = 'Accounting' INTERSECT SELECT T1.stu_fname FROM student AS T1 JOIN enroll AS T2 ON T1.stu_num = T2.stu_num JOIN CLASS AS T3 ON T2.class_code = T3.class_code JOIN course AS T4 ON T3.crs_code = T4.crs_code JOIN department AS T5 ON T5.dept_code = T4.dept_code WHERE T5.dept_name = 'Computer Info. Systems' [/SQL]


Question: What is the average gpa of the students enrolled in the course with code ACCT-211?

Context: CREATE TABLE enroll (stu_num VARCHAR, class_code VARCHAR); CREATE TABLE CLASS (class_code VARCHAR, crs_code VARCHAR); CREATE TABLE student (stu_gpa INTEGER, stu_num VARCHAR)

Answer: [SQL] SELECT AVG(T2.stu_gpa) FROM enroll AS T1 JOIN student AS T2 ON T1.stu_num = T2.stu_num JOIN CLASS AS T3 ON T1.class_code = T3.class_code WHERE T3.crs_code = 'ACCT-211' [/SQL]


Question: What is the first name, gpa and phone number of the top 5 students with highest gpa?

Context: CREATE TABLE student (stu_gpa VARCHAR, stu_phone VARCHAR, stu_fname VARCHAR)

Answer: [SQL] SELECT stu_gpa, stu_phone, stu_fname FROM student ORDER BY stu_gpa DESC LIMIT 5 [/SQL]


Question: What is the department name of the students with lowest gpa belongs to?

Context: CREATE TABLE student (dept_code VARCHAR); CREATE TABLE department (dept_name VARCHAR, dept_code VARCHAR)

Answer: [SQL] SELECT T2.dept_name FROM student AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code ORDER BY stu_gpa LIMIT 1 [/SQL]


Question: Find the first name and gpa of the students whose gpa is lower than the average gpa of all students.

Context: CREATE TABLE student (stu_fname VARCHAR, stu_gpa INTEGER)

Answer: [SQL] SELECT stu_fname, stu_gpa FROM student WHERE stu_gpa < (SELECT AVG(stu_gpa) FROM student) [/SQL]


Question: Find the name and address of the department that has the highest number of students.

Context: CREATE TABLE student (dept_code VARCHAR); CREATE TABLE department (dept_name VARCHAR, dept_address VARCHAR, dept_code VARCHAR)

Answer: [SQL] SELECT T2.dept_name, T2.dept_address FROM student AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code GROUP BY T1.dept_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the name, address, number of students in the departments that have the top 3 highest number of students.

Answer: [SQL] SELECT T2.dept_name, T2.dept_address, COUNT(*) FROM student AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code GROUP BY T1.dept_code ORDER BY COUNT(*) DESC LIMIT 3 [/SQL]


Question: Find the first name and office of the professor who is in the history department and has a Ph.D. degree.

Context: CREATE TABLE department (dept_code VARCHAR, dept_name VARCHAR); CREATE TABLE professor (prof_office VARCHAR, emp_num VARCHAR, dept_code VARCHAR, prof_high_degree VARCHAR); CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR)

Answer: [SQL] SELECT T1.emp_fname, T2.prof_office FROM employee AS T1 JOIN professor AS T2 ON T1.emp_num = T2.emp_num JOIN department AS T3 ON T3.dept_code = T2.dept_code WHERE T3.dept_name = 'History' AND T2.prof_high_degree = 'Ph.D.' [/SQL]


Question: Find the first names of all instructors who have taught some course and the course code.

Context: CREATE TABLE CLASS (crs_code VARCHAR, prof_num VARCHAR); CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR)

Answer: [SQL] SELECT T2.emp_fname, T1.crs_code FROM CLASS AS T1 JOIN employee AS T2 ON T1.prof_num = T2.emp_num [/SQL]


Question: Find the first names of all instructors who have taught some course and the course description.

Context: CREATE TABLE course (crs_description VARCHAR, crs_code VARCHAR); CREATE TABLE CLASS (prof_num VARCHAR, crs_code VARCHAR); CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR)

Answer: [SQL] SELECT T2.emp_fname, T3.crs_description FROM CLASS AS T1 JOIN employee AS T2 ON T1.prof_num = T2.emp_num JOIN course AS T3 ON T1.crs_code = T3.crs_code [/SQL]


Question: Find the first names and offices of all instructors who have taught some course and also find the course description.

Context: CREATE TABLE professor (prof_office VARCHAR, emp_num VARCHAR); CREATE TABLE course (crs_description VARCHAR, crs_code VARCHAR); CREATE TABLE CLASS (prof_num VARCHAR, crs_code VARCHAR); CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR)

Answer: [SQL] SELECT T2.emp_fname, T4.prof_office, T3.crs_description FROM CLASS AS T1 JOIN employee AS T2 ON T1.prof_num = T2.emp_num JOIN course AS T3 ON T1.crs_code = T3.crs_code JOIN professor AS T4 ON T2.emp_num = T4.emp_num [/SQL]


Question: Find the first names and offices of all instructors who have taught some course and the course description and the department name.

Context: CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR); CREATE TABLE department (dept_name VARCHAR, dept_code VARCHAR); CREATE TABLE course (crs_description VARCHAR, crs_code VARCHAR); CREATE TABLE CLASS (prof_num VARCHAR, crs_code VARCHAR); CREATE TABLE professor (prof_office VARCHAR, emp_num VARCHAR, dept_code VARCHAR)

Answer: [SQL] SELECT T2.emp_fname, T4.prof_office, T3.crs_description, T5.dept_name FROM CLASS AS T1 JOIN employee AS T2 ON T1.prof_num = T2.emp_num JOIN course AS T3 ON T1.crs_code = T3.crs_code JOIN professor AS T4 ON T2.emp_num = T4.emp_num JOIN department AS T5 ON T4.dept_code = T5.dept_code [/SQL]


Question: Find names of all students who took some course and the course description.

Context: CREATE TABLE enroll (stu_num VARCHAR, class_code VARCHAR); CREATE TABLE course (crs_description VARCHAR, crs_code VARCHAR); CREATE TABLE CLASS (class_code VARCHAR, crs_code VARCHAR); CREATE TABLE student (stu_fname VARCHAR, stu_lname VARCHAR, stu_num VARCHAR)

Answer: [SQL] SELECT T1.stu_fname, T1.stu_lname, T4.crs_description FROM student AS T1 JOIN enroll AS T2 ON T1.stu_num = T2.stu_num JOIN CLASS AS T3 ON T2.class_code = T3.class_code JOIN course AS T4 ON T3.crs_code = T4.crs_code [/SQL]


Question: Find names of all students who took some course and got A or C.

Context: CREATE TABLE enroll (stu_num VARCHAR, enroll_grade VARCHAR); CREATE TABLE student (stu_fname VARCHAR, stu_lname VARCHAR, stu_num VARCHAR)

Answer: [SQL] SELECT T1.stu_fname, T1.stu_lname FROM student AS T1 JOIN enroll AS T2 ON T1.stu_num = T2.stu_num WHERE T2.enroll_grade = 'C' OR T2.enroll_grade = 'A' [/SQL]


Question: Find the first names of all professors in the Accounting department who is teaching some course and the class room.

Context: CREATE TABLE CLASS (class_room VARCHAR, prof_num VARCHAR); CREATE TABLE professor (emp_num VARCHAR, dept_code VARCHAR); CREATE TABLE department (dept_code VARCHAR, dept_name VARCHAR); CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR)

Answer: [SQL] SELECT T2.emp_fname, T1.class_room FROM CLASS AS T1 JOIN employee AS T2 ON T1.prof_num = T2.emp_num JOIN professor AS T3 ON T2.emp_num = T3.emp_num JOIN department AS T4 ON T4.dept_code = T3.dept_code WHERE T4.dept_name = 'Accounting' [/SQL]


Question: Find the first names and degree of all professors who are teaching some class in Computer Info. Systems department.

Context: CREATE TABLE professor (prof_high_degree VARCHAR, emp_num VARCHAR, dept_code VARCHAR); CREATE TABLE department (dept_code VARCHAR, dept_name VARCHAR); CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR); CREATE TABLE CLASS (prof_num VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.emp_fname, T3.prof_high_degree FROM CLASS AS T1 JOIN employee AS T2 ON T1.prof_num = T2.emp_num JOIN professor AS T3 ON T2.emp_num = T3.emp_num JOIN department AS T4 ON T4.dept_code = T3.dept_code WHERE T4.dept_name = 'Computer Info. Systems' [/SQL]


Question: What is the last name of the student who got a grade A in the class with code 10018.

Context: CREATE TABLE enroll (stu_num VARCHAR, enroll_grade VARCHAR, class_code VARCHAR); CREATE TABLE student (stu_lname VARCHAR, stu_num VARCHAR)

Answer: [SQL] SELECT T1.stu_lname FROM student AS T1 JOIN enroll AS T2 ON T1.stu_num = T2.stu_num WHERE T2.enroll_grade = 'A' AND T2.class_code = 10018 [/SQL]


Question: Find the first name and office of history professor who did not get a Ph.D. degree.

Answer: [SQL] SELECT T2.emp_fname, T1.prof_office FROM professor AS T1 JOIN employee AS T2 ON T1.emp_num = T2.emp_num JOIN department AS T3 ON T1.dept_code = T3.dept_code WHERE T3.dept_name = 'History' AND T1.prof_high_degree <> 'Ph.D.' [/SQL]


Question: Find the first names of professors who are teaching more than one class.

Context: CREATE TABLE employee (emp_fname VARCHAR, emp_num VARCHAR); CREATE TABLE CLASS (prof_num VARCHAR)

Answer: [SQL] SELECT T2.emp_fname FROM CLASS AS T1 JOIN employee AS T2 ON T1.prof_num = T2.emp_num GROUP BY T1.prof_num HAVING COUNT(*) > 1 [/SQL]


Question: Find the first names of students who took exactly one class.

Context: CREATE TABLE enroll (stu_num VARCHAR); CREATE TABLE student (stu_fname VARCHAR, stu_num VARCHAR)

Answer: [SQL] SELECT T1.stu_fname FROM student AS T1 JOIN enroll AS T2 ON T1.stu_num = T2.stu_num GROUP BY T2.stu_num HAVING COUNT(*) = 1 [/SQL]


Question: Find the name of department that offers the class whose description has the word "Statistics".

Context: CREATE TABLE course (dept_code VARCHAR, crs_description VARCHAR); CREATE TABLE department (dept_name VARCHAR, dept_code VARCHAR)

Answer: [SQL] SELECT T2.dept_name FROM course AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code WHERE T1.crs_description LIKE '%Statistics%' [/SQL]


Question: What is the first name of the student whose last name starting with the letter S and is taking ACCT-211 class?

Context: CREATE TABLE enroll (stu_num VARCHAR, class_code VARCHAR); CREATE TABLE CLASS (class_code VARCHAR, crs_code VARCHAR); CREATE TABLE student (stu_fname VARCHAR, stu_num VARCHAR, stu_lname VARCHAR)

Answer: [SQL] SELECT T1.stu_fname FROM student AS T1 JOIN enroll AS T2 ON T1.stu_num = T2.stu_num JOIN CLASS AS T3 ON T2.class_code = T3.class_code WHERE T3.crs_code = 'ACCT-211' AND T1.stu_lname LIKE 'S%' [/SQL]


Question: How many clubs are there?

Context: CREATE TABLE club (Id VARCHAR)

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


Question: List the distinct region of clubs in ascending alphabetical order.

Context: CREATE TABLE club (Region VARCHAR)

Answer: [SQL] SELECT DISTINCT Region FROM club ORDER BY Region [/SQL]


Question: What is the average number of gold medals for clubs?

Context: CREATE TABLE club_rank (Gold INTEGER)

Answer: [SQL] SELECT AVG(Gold) FROM club_rank [/SQL]


Question: What are the types and countries of competitions?

Context: CREATE TABLE competition (Competition_type VARCHAR, Country VARCHAR)

Answer: [SQL] SELECT Competition_type, Country FROM competition [/SQL]


Question: What are the distinct years in which the competitions type is not "Tournament"?

Context: CREATE TABLE competition (YEAR VARCHAR, Competition_type VARCHAR)

Answer: [SQL] SELECT DISTINCT YEAR FROM competition WHERE Competition_type <> "Tournament" [/SQL]


Question: What are the maximum and minimum number of silver medals for clubs.

Context: CREATE TABLE club_rank (Silver INTEGER)

Answer: [SQL] SELECT MAX(Silver), MIN(Silver) FROM club_rank [/SQL]


Question: How many clubs have total medals less than 10?

Context: CREATE TABLE club_rank (Total INTEGER)

Answer: [SQL] SELECT COUNT(*) FROM club_rank WHERE Total < 10 [/SQL]