schema
stringlengths
144
5.45k
question
stringlengths
16
224
query
stringlengths
18
577
hardness
stringclasses
5 values
CREATE TABLE actor (actor_id number, first_name text, last_name text, last_update time); CREATE TABLE address (address_id number, address text, address2 text, district text, city_id number, postal_code text, phone text, last_update time); CREATE TABLE category (category_id number, name text, last_update time); CREATE TABLE city (city_id number, city text, country_id number, last_update time); CREATE TABLE country (country_id number, country text, last_update time); CREATE TABLE customer (customer_id number, store_id number, first_name text, last_name text, email text, address_id number, active boolean, create_date time, last_update time); CREATE TABLE film (film_id number, title text, description text, release_year time, language_id number, original_language_id number, rental_duration number, rental_rate number, length number, replacement_cost number, rating text, special_features text, last_update time); CREATE TABLE film_actor (actor_id number, film_id number, last_update time); CREATE TABLE film_category (film_id number, category_id number, last_update time); CREATE TABLE film_text (film_id number, title text, description text); CREATE TABLE inventory (inventory_id number, film_id number, store_id number, last_update time); CREATE TABLE language (language_id number, name text, last_update time); CREATE TABLE payment (payment_id number, customer_id number, staff_id number, rental_id number, amount number, payment_date time, last_update time); CREATE TABLE rental (rental_id number, rental_date time, inventory_id number, customer_id number, return_date time, staff_id number, last_update time); CREATE TABLE staff (staff_id number, first_name text, last_name text, address_id number, picture others, email text, store_id number, active boolean, username text, password text, last_update time); CREATE TABLE store (store_id number, manager_staff_id number, address_id number, last_update time);
What is the largest payment amount?
SELECT amount FROM payment ORDER BY amount DESC LIMIT 1
medium
CREATE TABLE actor (actor_id number, first_name text, last_name text, last_update time); CREATE TABLE address (address_id number, address text, address2 text, district text, city_id number, postal_code text, phone text, last_update time); CREATE TABLE category (category_id number, name text, last_update time); CREATE TABLE city (city_id number, city text, country_id number, last_update time); CREATE TABLE country (country_id number, country text, last_update time); CREATE TABLE customer (customer_id number, store_id number, first_name text, last_name text, email text, address_id number, active boolean, create_date time, last_update time); CREATE TABLE film (film_id number, title text, description text, release_year time, language_id number, original_language_id number, rental_duration number, rental_rate number, length number, replacement_cost number, rating text, special_features text, last_update time); CREATE TABLE film_actor (actor_id number, film_id number, last_update time); CREATE TABLE film_category (film_id number, category_id number, last_update time); CREATE TABLE film_text (film_id number, title text, description text); CREATE TABLE inventory (inventory_id number, film_id number, store_id number, last_update time); CREATE TABLE language (language_id number, name text, last_update time); CREATE TABLE payment (payment_id number, customer_id number, staff_id number, rental_id number, amount number, payment_date time, last_update time); CREATE TABLE rental (rental_id number, rental_date time, inventory_id number, customer_id number, return_date time, staff_id number, last_update time); CREATE TABLE staff (staff_id number, first_name text, last_name text, address_id number, picture others, email text, store_id number, active boolean, username text, password text, last_update time); CREATE TABLE store (store_id number, manager_staff_id number, address_id number, last_update time);
Return the amount of the largest payment.
SELECT amount FROM payment ORDER BY amount DESC LIMIT 1
medium
CREATE TABLE actor (actor_id number, first_name text, last_name text, last_update time); CREATE TABLE address (address_id number, address text, address2 text, district text, city_id number, postal_code text, phone text, last_update time); CREATE TABLE category (category_id number, name text, last_update time); CREATE TABLE city (city_id number, city text, country_id number, last_update time); CREATE TABLE country (country_id number, country text, last_update time); CREATE TABLE customer (customer_id number, store_id number, first_name text, last_name text, email text, address_id number, active boolean, create_date time, last_update time); CREATE TABLE film (film_id number, title text, description text, release_year time, language_id number, original_language_id number, rental_duration number, rental_rate number, length number, replacement_cost number, rating text, special_features text, last_update time); CREATE TABLE film_actor (actor_id number, film_id number, last_update time); CREATE TABLE film_category (film_id number, category_id number, last_update time); CREATE TABLE film_text (film_id number, title text, description text); CREATE TABLE inventory (inventory_id number, film_id number, store_id number, last_update time); CREATE TABLE language (language_id number, name text, last_update time); CREATE TABLE payment (payment_id number, customer_id number, staff_id number, rental_id number, amount number, payment_date time, last_update time); CREATE TABLE rental (rental_id number, rental_date time, inventory_id number, customer_id number, return_date time, staff_id number, last_update time); CREATE TABLE staff (staff_id number, first_name text, last_name text, address_id number, picture others, email text, store_id number, active boolean, username text, password text, last_update time); CREATE TABLE store (store_id number, manager_staff_id number, address_id number, last_update time);
Where does the staff member with the first name Elsa live?
SELECT T2.address FROM staff AS T1 JOIN address AS T2 ON T1.address_id = T2.address_id WHERE T1.first_name = 'Elsa'
medium
CREATE TABLE actor (actor_id number, first_name text, last_name text, last_update time); CREATE TABLE address (address_id number, address text, address2 text, district text, city_id number, postal_code text, phone text, last_update time); CREATE TABLE category (category_id number, name text, last_update time); CREATE TABLE city (city_id number, city text, country_id number, last_update time); CREATE TABLE country (country_id number, country text, last_update time); CREATE TABLE customer (customer_id number, store_id number, first_name text, last_name text, email text, address_id number, active boolean, create_date time, last_update time); CREATE TABLE film (film_id number, title text, description text, release_year time, language_id number, original_language_id number, rental_duration number, rental_rate number, length number, replacement_cost number, rating text, special_features text, last_update time); CREATE TABLE film_actor (actor_id number, film_id number, last_update time); CREATE TABLE film_category (film_id number, category_id number, last_update time); CREATE TABLE film_text (film_id number, title text, description text); CREATE TABLE inventory (inventory_id number, film_id number, store_id number, last_update time); CREATE TABLE language (language_id number, name text, last_update time); CREATE TABLE payment (payment_id number, customer_id number, staff_id number, rental_id number, amount number, payment_date time, last_update time); CREATE TABLE rental (rental_id number, rental_date time, inventory_id number, customer_id number, return_date time, staff_id number, last_update time); CREATE TABLE staff (staff_id number, first_name text, last_name text, address_id number, picture others, email text, store_id number, active boolean, username text, password text, last_update time); CREATE TABLE store (store_id number, manager_staff_id number, address_id number, last_update time);
Give the address of the staff member who has the first name Elsa.
SELECT T2.address FROM staff AS T1 JOIN address AS T2 ON T1.address_id = T2.address_id WHERE T1.first_name = 'Elsa'
medium
CREATE TABLE actor (actor_id number, first_name text, last_name text, last_update time); CREATE TABLE address (address_id number, address text, address2 text, district text, city_id number, postal_code text, phone text, last_update time); CREATE TABLE category (category_id number, name text, last_update time); CREATE TABLE city (city_id number, city text, country_id number, last_update time); CREATE TABLE country (country_id number, country text, last_update time); CREATE TABLE customer (customer_id number, store_id number, first_name text, last_name text, email text, address_id number, active boolean, create_date time, last_update time); CREATE TABLE film (film_id number, title text, description text, release_year time, language_id number, original_language_id number, rental_duration number, rental_rate number, length number, replacement_cost number, rating text, special_features text, last_update time); CREATE TABLE film_actor (actor_id number, film_id number, last_update time); CREATE TABLE film_category (film_id number, category_id number, last_update time); CREATE TABLE film_text (film_id number, title text, description text); CREATE TABLE inventory (inventory_id number, film_id number, store_id number, last_update time); CREATE TABLE language (language_id number, name text, last_update time); CREATE TABLE payment (payment_id number, customer_id number, staff_id number, rental_id number, amount number, payment_date time, last_update time); CREATE TABLE rental (rental_id number, rental_date time, inventory_id number, customer_id number, return_date time, staff_id number, last_update time); CREATE TABLE staff (staff_id number, first_name text, last_name text, address_id number, picture others, email text, store_id number, active boolean, username text, password text, last_update time); CREATE TABLE store (store_id number, manager_staff_id number, address_id number, last_update time);
What are the first names of customers who have not rented any films after '2005-08-23 02:06:01'?
SELECT first_name FROM customer WHERE customer_id NOT IN( SELECT customer_id FROM rental WHERE rental_date > '2005-08-23 02:06:01' )
hard
CREATE TABLE actor (actor_id number, first_name text, last_name text, last_update time); CREATE TABLE address (address_id number, address text, address2 text, district text, city_id number, postal_code text, phone text, last_update time); CREATE TABLE category (category_id number, name text, last_update time); CREATE TABLE city (city_id number, city text, country_id number, last_update time); CREATE TABLE country (country_id number, country text, last_update time); CREATE TABLE customer (customer_id number, store_id number, first_name text, last_name text, email text, address_id number, active boolean, create_date time, last_update time); CREATE TABLE film (film_id number, title text, description text, release_year time, language_id number, original_language_id number, rental_duration number, rental_rate number, length number, replacement_cost number, rating text, special_features text, last_update time); CREATE TABLE film_actor (actor_id number, film_id number, last_update time); CREATE TABLE film_category (film_id number, category_id number, last_update time); CREATE TABLE film_text (film_id number, title text, description text); CREATE TABLE inventory (inventory_id number, film_id number, store_id number, last_update time); CREATE TABLE language (language_id number, name text, last_update time); CREATE TABLE payment (payment_id number, customer_id number, staff_id number, rental_id number, amount number, payment_date time, last_update time); CREATE TABLE rental (rental_id number, rental_date time, inventory_id number, customer_id number, return_date time, staff_id number, last_update time); CREATE TABLE staff (staff_id number, first_name text, last_name text, address_id number, picture others, email text, store_id number, active boolean, username text, password text, last_update time); CREATE TABLE store (store_id number, manager_staff_id number, address_id number, last_update time);
Return the first names of customers who did not rented a film after the date '2005-08-23 02:06:01'.
SELECT first_name FROM customer WHERE customer_id NOT IN( SELECT customer_id FROM rental WHERE rental_date > '2005-08-23 02:06:01' )
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
How many bank branches are there?
SELECT count(*) FROM bank
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Count the number of bank branches.
SELECT count(*) FROM bank
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
How many customers are there?
SELECT sum(no_of_customers) FROM bank
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the total number of customers across banks?
SELECT sum(no_of_customers) FROM bank
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the number of customers in the banks at New York City.
SELECT sum(no_of_customers) FROM bank WHERE city = 'New York City'
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the total number of customers who use banks in New York City?
SELECT sum(no_of_customers) FROM bank WHERE city = 'New York City'
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the average number of customers in all banks of Utah state.
SELECT avg(no_of_customers) FROM bank WHERE state = 'Utah'
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the average number of customers across banks in the state of Utah?
SELECT avg(no_of_customers) FROM bank WHERE state = 'Utah'
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the average number of customers cross all banks.
SELECT avg(no_of_customers) FROM bank
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the average number of bank customers?
SELECT avg(no_of_customers) FROM bank
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the city and state of the bank branch named morningside.
SELECT city , state FROM bank WHERE bname = 'morningside'
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What city and state is the bank with the name morningside in?
SELECT city , state FROM bank WHERE bname = 'morningside'
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the branch names of banks in the New York state.
SELECT bname FROM bank WHERE state = 'New York'
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of banks in the state of New York?
SELECT bname FROM bank WHERE state = 'New York'
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
List the name of all customers sorted by their account balance in ascending order.
SELECT cust_name FROM customer ORDER BY acc_bal
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of all customers, ordered by account balance?
SELECT cust_name FROM customer ORDER BY acc_bal
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
List the name of all different customers who have some loan sorted by their total loan amount.
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)
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of the different customers who have taken out a loan, ordered by the total amount that they have taken?
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)
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the state, account type, and credit score of the customer whose number of loan is 0.
SELECT state , acc_type , credit_score FROM customer WHERE no_of_loans = 0
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the states, account types, and credit scores for customers who have 0 loans?
SELECT state , acc_type , credit_score FROM customer WHERE no_of_loans = 0
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the number of different cities which banks are located at.
SELECT count(DISTINCT city) FROM bank
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
In how many different cities are banks located?
SELECT count(DISTINCT city) FROM bank
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the number of different states which banks are located at.
SELECT count(DISTINCT state) FROM bank
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
In how many different states are banks located?
SELECT count(DISTINCT state) FROM bank
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
How many distinct types of accounts are there?
SELECT count(DISTINCT acc_type) FROM customer
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Count the number of different account types.
SELECT count(DISTINCT acc_type) FROM customer
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name and account balance of the customer whose name includes the letter ‘a’.
SELECT cust_name , acc_bal FROM customer WHERE cust_name LIKE '%a%'
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names and account balances of customers with the letter a in their names?
SELECT cust_name , acc_bal FROM customer WHERE cust_name LIKE '%a%'
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the total account balance of each customer from Utah or Texas.
SELECT sum(acc_bal) FROM customer WHERE state = 'Utah' OR state = 'Texas'
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the total account balances for each customer from Utah or Texas?
SELECT sum(acc_bal) FROM customer WHERE state = 'Utah' OR state = 'Texas'
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of customers who have both saving and checking account types.
SELECT cust_name FROM customer WHERE acc_type = 'saving' INTERSECT SELECT cust_name FROM customer WHERE acc_type = 'checking'
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of customers who have both savings and checking accounts?
SELECT cust_name FROM customer WHERE acc_type = 'saving' INTERSECT SELECT cust_name FROM customer WHERE acc_type = 'checking'
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of customers who do not have an saving account.
SELECT cust_name FROM customer EXCEPT SELECT cust_name FROM customer WHERE acc_type = 'saving'
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of customers who do not have saving accounts?
SELECT cust_name FROM customer EXCEPT SELECT cust_name FROM customer WHERE acc_type = 'saving'
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of customers who do not have a loan with a type of Mortgages.
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'
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of customers who have not taken a Mortage loan?
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'
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of customers who have loans of both Mortgages and Auto.
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'
extra
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of customers who have taken both Mortgage and Auto loans?
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'
extra
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of customers whose credit score is below the average credit scores of all customers.
SELECT cust_name FROM customer WHERE credit_score < (SELECT avg(credit_score) FROM customer)
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of customers with credit score less than the average credit score across customers?
SELECT cust_name FROM customer WHERE credit_score < (SELECT avg(credit_score) FROM customer)
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the branch name of the bank that has the most number of customers.
SELECT bname FROM bank ORDER BY no_of_customers DESC LIMIT 1
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the name of the bank branch with the greatest number of customers?
SELECT bname FROM bank ORDER BY no_of_customers DESC LIMIT 1
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of customer who has the lowest credit score.
SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the name of the customer with the worst credit score?
SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name, account type, and account balance of the customer who has the highest credit score.
SELECT cust_name , acc_type , acc_bal FROM customer ORDER BY credit_score DESC LIMIT 1
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the name, account type, and account balance corresponding to the customer with the highest credit score?
SELECT cust_name , acc_type , acc_bal FROM customer ORDER BY credit_score DESC LIMIT 1
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of customer who has the highest amount of loans.
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name ORDER BY sum(T2.amount) DESC LIMIT 1
extra
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the name of the customer who has greatest total loan amount?
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
extra
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the state which has the most number of customers.
SELECT state FROM bank GROUP BY state ORDER BY sum(no_of_customers) DESC LIMIT 1
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Which state has the greatest total number of bank customers?
SELECT state FROM bank GROUP BY state ORDER BY sum(no_of_customers) DESC LIMIT 1
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
For each account type, find the average account balance of customers with credit score lower than 50.
SELECT avg(acc_bal) , acc_type FROM customer WHERE credit_score < 50 GROUP BY acc_type
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the average account balance of customers with credit score below 50 for the different account types?
SELECT avg(acc_bal) , acc_type FROM customer WHERE credit_score < 50 GROUP BY acc_type
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
For each state, find the total account balance of customers whose credit score is above 100.
SELECT sum(acc_bal) , state FROM customer WHERE credit_score > 100 GROUP BY state
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the total account balance for customers with a credit score of above 100 for the different states?
SELECT sum(acc_bal) , state FROM customer WHERE credit_score > 100 GROUP BY state
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the total amount of loans offered by each bank branch.
SELECT sum(amount) , T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of the different bank branches, and what are their total loan amounts?
SELECT sum(amount) , T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of customers who have more than one loan.
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name HAVING count(*) > 1
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of customers who have taken out more than one loan?
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name HAVING count(*) > 1
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name and account balance of the customers who have loans with a total amount of more than 5000.
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
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names and account balances for customers who have taken a total amount of more than 5000 in loans?
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
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of bank branch that provided the greatest total amount of loans.
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
extra
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the name of the bank branch that has lent the greatest amount?
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
extra
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of bank branch that provided the greatest total amount of loans to customers with credit score is less than 100.
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
extra
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the name of the bank branch that has lended the largest total amount in loans, specifically to customers with credit scores below 100?
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
extra
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name of bank branches that provided some loans.
SELECT DISTINCT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of the different banks that have provided loans?
SELECT DISTINCT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id
easy
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the name and credit score of the customers who have some loans.
SELECT DISTINCT T1.cust_name , T1.credit_score FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the different names and credit scores of customers who have taken a loan?
SELECT DISTINCT T1.cust_name , T1.credit_score FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the the name of the customers who have a loan with amount more than 3000.
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE amount > 3000
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of customers who have a loan of more than 3000 in amount?
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE amount > 3000
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the city and name of bank branches that provide business loans.
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'
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names and cities of bank branches that offer loans for business?
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'
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the names of bank branches that have provided a loan to any customer whose credit score is below 100.
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
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What are the names of banks that have loaned money to customers with credit scores below 100?
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
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the total amount of loans provided by bank branches in the state of New York.
SELECT sum(T2.amount) FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T1.state = 'New York'
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the total amount of money loaned by banks in New York state?
SELECT sum(T2.amount) FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T1.state = 'New York'
medium
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the average credit score of the customers who have some loan.
SELECT avg(credit_score) FROM customer WHERE cust_id IN (SELECT cust_id FROM loan)
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the average credit score for customers who have taken a loan?
SELECT avg(credit_score) FROM customer WHERE cust_id IN (SELECT cust_id FROM loan)
hard
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
Find the average credit score of the customers who do not have any loan.
SELECT avg(credit_score) FROM customer WHERE cust_id NOT IN (SELECT cust_id FROM loan)
extra
CREATE TABLE bank (branch_ID number, bname text, no_of_customers number, city text, state text); CREATE TABLE customer (cust_ID text, cust_name text, acc_type text, acc_bal number, no_of_loans number, credit_score number, branch_ID number, state text); CREATE TABLE loan (loan_ID text, loan_type text, cust_ID text, branch_ID text, amount number);
What is the average credit score for customers who have never taken a loan?
SELECT avg(credit_score) FROM customer WHERE cust_id NOT IN (SELECT cust_id FROM loan)
extra
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
How many assessment notes are there in total?
SELECT count(*) FROM ASSESSMENT_NOTES
easy
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
What are the dates of the assessment notes?
SELECT date_of_notes FROM Assessment_Notes
easy
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
How many addresses have zip code 197?
SELECT count(*) FROM ADDRESSES WHERE zip_postcode = "197"
easy
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
How many distinct incident type codes are there?
SELECT count(DISTINCT incident_type_code) FROM Behavior_Incident
easy
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
Return all distinct detention type codes.
SELECT DISTINCT detention_type_code FROM Detention
easy
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
What are the start and end dates for incidents with incident type code "NOISE"?
SELECT date_incident_start , date_incident_end FROM Behavior_Incident WHERE incident_type_code = "NOISE"
medium
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
Return all detention summaries.
SELECT detention_summary FROM Detention
easy
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
Return the cell phone number and email address for all students.
SELECT cell_mobile_number , email_address FROM STUDENTS
medium
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
What is the email of the student with first name "Emma" and last name "Rohan"?
SELECT email_address FROM Students WHERE first_name = "Emma" AND last_name = "Rohan"
medium
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
How many distinct students have been in detention?
SELECT count(DISTINCT student_id) FROM Students_in_Detention
easy
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
What is the gender of the teacher with last name "Medhurst"?
SELECT gender FROM TEACHERS WHERE last_name = "Medhurst"
easy
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
What is the incident type description for the incident type with code "VIOLENCE"?
SELECT incident_type_description FROM Ref_Incident_Type WHERE incident_type_code = "VIOLENCE"
easy
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
Find the maximum and minimum monthly rental for all student addresses.
SELECT max(monthly_rental) , min(monthly_rental) FROM Student_Addresses
medium
CREATE TABLE Ref_Address_Types (address_type_code text, address_type_description text); CREATE TABLE Ref_Detention_Type (detention_type_code text, detention_type_description text); CREATE TABLE Ref_Incident_Type (incident_type_code text, incident_type_description text); CREATE TABLE Addresses (address_id number, line_1 text, line_2 text, line_3 text, city text, zip_postcode text, state_province_county text, country text, other_address_details text); CREATE TABLE Students (student_id number, address_id number, first_name text, middle_name text, last_name text, cell_mobile_number text, email_address text, date_first_rental time, date_left_university time, other_student_details text); CREATE TABLE Teachers (teacher_id number, address_id number, first_name text, middle_name text, last_name text, gender text, cell_mobile_number text, email_address text, other_details text); CREATE TABLE Assessment_Notes (notes_id number, student_id number, teacher_id number, date_of_notes time, text_of_notes text, other_details text); CREATE TABLE Behavior_Incident (incident_id number, incident_type_code text, student_id number, date_incident_start time, date_incident_end time, incident_summary text, recommendations text, other_details text); CREATE TABLE Detention (detention_id number, detention_type_code text, teacher_id number, datetime_detention_start time, datetime_detention_end time, detention_summary text, other_details text); CREATE TABLE Student_Addresses (student_id number, address_id number, date_address_from time, date_address_to time, monthly_rental number, other_details text); CREATE TABLE Students_in_Detention (student_id number, detention_id number, incident_id number);
Find the first names of teachers whose email address contains the word "man".
SELECT first_name FROM Teachers WHERE email_address LIKE '%man%'
medium