db_id
stringclasses
146 values
question
stringlengths
3
224
sql
stringlengths
18
577
database_schema
stringclasses
146 values
sakila_1
What is the largest payment amount?
SELECT amount FROM payment ORDER BY amount DESC LIMIT 1
CREATE TABLE actor ( actor_id SMALLINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id) ) 3 rows from actor table: actor_id first_name last_name last_update 1 PENELOPE GUINESS 2006-02-15 04:34:33 2 NICK WAHLBERG 2006-02-15 04:34:33 3 ED CHASE 2006-02-15 04:34:33 CREATE TABLE address ( address_id SMALLINT UNSIGNED NOT NULL, address VARCHAR(50) NOT NULL, address2 VARCHAR(50) DEFAULT NULL, district VARCHAR(20) NOT NULL, city_id SMALLINT UNSIGNED NOT NULL, postal_code VARCHAR(10) DEFAULT NULL, phone VARCHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (address_id), FOREIGN KEY (city_id) REFERENCES city (city_id) ) 3 rows from address table: address_id address address2 district city_id postal_code phone last_update 1 47 MySakila Drive None Alberta 300 2006-02-15 04:45:30 2 28 MySQL Boulevard None QLD 576 2006-02-15 04:45:30 3 23 Workhaven Lane None Alberta 300 14033335568 2006-02-15 04:45:30 CREATE TABLE category ( category_id TINYINT UNSIGNED NOT NULL, name VARCHAR(25) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (category_id) ) 3 rows from category table: category_id name last_update 1 Action 2006-02-15 04:46:27 2 Animation 2006-02-15 04:46:27 3 Children 2006-02-15 04:46:27 CREATE TABLE city ( city_id SMALLINT UNSIGNED NOT NULL, city VARCHAR(50) NOT NULL, country_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (city_id), FOREIGN KEY (country_id) REFERENCES country (country_id) ) 3 rows from city table: city_id city country_id last_update 1 A Corua (La Corua) 87 2006-02-15 04:45:25 2 Abha 82 2006-02-15 04:45:25 3 Abu Dhabi 101 2006-02-15 04:45:25 CREATE TABLE country ( country_id SMALLINT UNSIGNED NOT NULL, country VARCHAR(50) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (country_id) ) 3 rows from country table: country_id country last_update 1 Afghanistan 2006-02-15 04:44:00 2 Algeria 2006-02-15 04:44:00 3 American Samoa 2006-02-15 04:44:00 CREATE TABLE customer ( customer_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, email VARCHAR(50) DEFAULT NULL, address_id SMALLINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, create_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (customer_id), FOREIGN KEY (address_id) REFERENCES address (address_id), FOREIGN KEY (store_id) REFERENCES store (store_id) ) 3 rows from customer table: customer_id store_id first_name last_name email address_id active create_date last_update 1 1 MARY SMITH MARY.SMITH@sakilacustomer.org 5 1 2006-02-14 22:04:36 2006-02-15 04:57:20 2 1 PATRICIA JOHNSON PATRICIA.JOHNSON@sakilacustomer.org 6 1 2006-02-14 22:04:36 2006-02-15 04:57:20 3 1 LINDA WILLIAMS LINDA.WILLIAMS@sakilacustomer.org 7 1 2006-02-14 22:04:36 2006-02-15 04:57:20 CREATE TABLE film ( film_id SMALLINT UNSIGNED NOT NULL, title VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, release_year YEAR DEFAULT NULL, language_id TINYINT UNSIGNED NOT NULL, original_language_id TINYINT UNSIGNED DEFAULT NULL, rental_duration TINYINT UNSIGNED NOT NULL DEFAULT 3, rental_rate DECIMAL(4,2) NOT NULL DEFAULT 4.99, length SMALLINT UNSIGNED DEFAULT NULL, replacement_cost DECIMAL(5,2) NOT NULL DEFAULT 19.99, rating DEFAULT 'G', special_features DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id), FOREIGN KEY (language_id) REFERENCES language (language_id), FOREIGN KEY (original_language_id) REFERENCES language (language_id) ) 3 rows from film table: film_id title description release_year language_id original_language_id rental_duration rental_rate length replacement_cost rating special_features last_update 1 ACADEMY DINOSAUR A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies 2006 1 None 6 0.99 86 20.99 PG Deleted Scenes,Behind the Scenes 2006-02-15 05:03:42 2 ACE GOLDFINGER A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China 2006 1 None 3 4.99 48 12.99 G Trailers,Deleted Scenes 2006-02-15 05:03:42 3 ADAPTATION HOLES A Astounding Reflection of a Lumberjack And a Car who must Sink a Lumberjack in A Baloon Factory 2006 1 None 7 2.99 50 18.99 NC-17 Trailers,Deleted Scenes 2006-02-15 05:03:42 CREATE TABLE film_actor ( actor_id SMALLINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id,film_id), FOREIGN KEY (actor_id) REFERENCES actor (actor_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from film_actor table: actor_id film_id last_update 1 1 2006-02-15 05:05:03 1 23 2006-02-15 05:05:03 1 25 2006-02-15 05:05:03 CREATE TABLE film_category ( film_id SMALLINT UNSIGNED NOT NULL, category_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id, category_id), FOREIGN KEY (film_id) REFERENCES film (film_id), FOREIGN KEY (category_id) REFERENCES category (category_id) ) 3 rows from film_category table: film_id category_id last_update 1 6 2006-02-15 05:07:09 2 11 2006-02-15 05:07:09 3 6 2006-02-15 05:07:09 CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ) 3 rows from film_text table: Empty DataFrame Columns: [film_id, title, description] Index: [] CREATE TABLE inventory ( inventory_id MEDIUMINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (inventory_id), FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from inventory table: inventory_id film_id store_id last_update 1 1 1 2006-02-15 05:09:17 2 1 1 2006-02-15 05:09:17 3 1 1 2006-02-15 05:09:17 CREATE TABLE language ( language_id TINYINT UNSIGNED NOT NULL, name CHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (language_id) ) 3 rows from language table: Empty DataFrame Columns: [language_id, name, last_update] Index: [] CREATE TABLE payment ( payment_id SMALLINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, staff_id TINYINT UNSIGNED NOT NULL, rental_id INT DEFAULT NULL, amount DECIMAL(5,2) NOT NULL, payment_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (payment_id), FOREIGN KEY (rental_id) REFERENCES rental (rental_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id) ) 3 rows from payment table: payment_id customer_id staff_id rental_id amount payment_date last_update 1 1 1 76 2.99 2005-05-25 11:30:37 2006-02-15 22:12:30 2 1 1 573 0.99 2005-05-28 10:35:23 2006-02-15 22:12:30 3 1 1 1185 5.99 2005-06-15 00:54:12 2006-02-15 22:12:30 CREATE TABLE rental ( rental_id INT NOT NULL, rental_date DATETIME NOT NULL, inventory_id MEDIUMINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, return_date DATETIME DEFAULT NULL, staff_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (rental_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id), FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id) ) 3 rows from rental table: rental_id rental_date inventory_id customer_id return_date staff_id last_update 1 2005-05-24 22:53:30 367 130 2005-05-26 22:04:30 1 2006-02-15 21:30:53 2 2005-05-24 22:54:33 1525 459 2005-05-28 19:40:33 1 2006-02-15 21:30:53 3 2005-05-24 23:03:39 1711 408 2005-06-01 22:12:39 1 2006-02-15 21:30:53 CREATE TABLE staff ( staff_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, picture BLOB DEFAULT NULL, email VARCHAR(50) DEFAULT NULL, store_id TINYINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, username VARCHAR(16) NOT NULL, password VARCHAR(40) DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (staff_id), --FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from staff table: Empty DataFrame Columns: [staff_id, first_name, last_name, address_id, picture, email, store_id, active, username, password, last_update] Index: [] CREATE TABLE store ( store_id TINYINT UNSIGNED NOT NULL, manager_staff_id TINYINT UNSIGNED NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (store_id), FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from store table: Empty DataFrame Columns: [store_id, manager_staff_id, address_id, last_update] Index: []
sakila_1
Return the amount of the largest payment.
SELECT amount FROM payment ORDER BY amount DESC LIMIT 1
CREATE TABLE actor ( actor_id SMALLINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id) ) 3 rows from actor table: actor_id first_name last_name last_update 1 PENELOPE GUINESS 2006-02-15 04:34:33 2 NICK WAHLBERG 2006-02-15 04:34:33 3 ED CHASE 2006-02-15 04:34:33 CREATE TABLE address ( address_id SMALLINT UNSIGNED NOT NULL, address VARCHAR(50) NOT NULL, address2 VARCHAR(50) DEFAULT NULL, district VARCHAR(20) NOT NULL, city_id SMALLINT UNSIGNED NOT NULL, postal_code VARCHAR(10) DEFAULT NULL, phone VARCHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (address_id), FOREIGN KEY (city_id) REFERENCES city (city_id) ) 3 rows from address table: address_id address address2 district city_id postal_code phone last_update 1 47 MySakila Drive None Alberta 300 2006-02-15 04:45:30 2 28 MySQL Boulevard None QLD 576 2006-02-15 04:45:30 3 23 Workhaven Lane None Alberta 300 14033335568 2006-02-15 04:45:30 CREATE TABLE category ( category_id TINYINT UNSIGNED NOT NULL, name VARCHAR(25) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (category_id) ) 3 rows from category table: category_id name last_update 1 Action 2006-02-15 04:46:27 2 Animation 2006-02-15 04:46:27 3 Children 2006-02-15 04:46:27 CREATE TABLE city ( city_id SMALLINT UNSIGNED NOT NULL, city VARCHAR(50) NOT NULL, country_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (city_id), FOREIGN KEY (country_id) REFERENCES country (country_id) ) 3 rows from city table: city_id city country_id last_update 1 A Corua (La Corua) 87 2006-02-15 04:45:25 2 Abha 82 2006-02-15 04:45:25 3 Abu Dhabi 101 2006-02-15 04:45:25 CREATE TABLE country ( country_id SMALLINT UNSIGNED NOT NULL, country VARCHAR(50) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (country_id) ) 3 rows from country table: country_id country last_update 1 Afghanistan 2006-02-15 04:44:00 2 Algeria 2006-02-15 04:44:00 3 American Samoa 2006-02-15 04:44:00 CREATE TABLE customer ( customer_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, email VARCHAR(50) DEFAULT NULL, address_id SMALLINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, create_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (customer_id), FOREIGN KEY (address_id) REFERENCES address (address_id), FOREIGN KEY (store_id) REFERENCES store (store_id) ) 3 rows from customer table: customer_id store_id first_name last_name email address_id active create_date last_update 1 1 MARY SMITH MARY.SMITH@sakilacustomer.org 5 1 2006-02-14 22:04:36 2006-02-15 04:57:20 2 1 PATRICIA JOHNSON PATRICIA.JOHNSON@sakilacustomer.org 6 1 2006-02-14 22:04:36 2006-02-15 04:57:20 3 1 LINDA WILLIAMS LINDA.WILLIAMS@sakilacustomer.org 7 1 2006-02-14 22:04:36 2006-02-15 04:57:20 CREATE TABLE film ( film_id SMALLINT UNSIGNED NOT NULL, title VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, release_year YEAR DEFAULT NULL, language_id TINYINT UNSIGNED NOT NULL, original_language_id TINYINT UNSIGNED DEFAULT NULL, rental_duration TINYINT UNSIGNED NOT NULL DEFAULT 3, rental_rate DECIMAL(4,2) NOT NULL DEFAULT 4.99, length SMALLINT UNSIGNED DEFAULT NULL, replacement_cost DECIMAL(5,2) NOT NULL DEFAULT 19.99, rating DEFAULT 'G', special_features DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id), FOREIGN KEY (language_id) REFERENCES language (language_id), FOREIGN KEY (original_language_id) REFERENCES language (language_id) ) 3 rows from film table: film_id title description release_year language_id original_language_id rental_duration rental_rate length replacement_cost rating special_features last_update 1 ACADEMY DINOSAUR A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies 2006 1 None 6 0.99 86 20.99 PG Deleted Scenes,Behind the Scenes 2006-02-15 05:03:42 2 ACE GOLDFINGER A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China 2006 1 None 3 4.99 48 12.99 G Trailers,Deleted Scenes 2006-02-15 05:03:42 3 ADAPTATION HOLES A Astounding Reflection of a Lumberjack And a Car who must Sink a Lumberjack in A Baloon Factory 2006 1 None 7 2.99 50 18.99 NC-17 Trailers,Deleted Scenes 2006-02-15 05:03:42 CREATE TABLE film_actor ( actor_id SMALLINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id,film_id), FOREIGN KEY (actor_id) REFERENCES actor (actor_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from film_actor table: actor_id film_id last_update 1 1 2006-02-15 05:05:03 1 23 2006-02-15 05:05:03 1 25 2006-02-15 05:05:03 CREATE TABLE film_category ( film_id SMALLINT UNSIGNED NOT NULL, category_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id, category_id), FOREIGN KEY (film_id) REFERENCES film (film_id), FOREIGN KEY (category_id) REFERENCES category (category_id) ) 3 rows from film_category table: film_id category_id last_update 1 6 2006-02-15 05:07:09 2 11 2006-02-15 05:07:09 3 6 2006-02-15 05:07:09 CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ) 3 rows from film_text table: Empty DataFrame Columns: [film_id, title, description] Index: [] CREATE TABLE inventory ( inventory_id MEDIUMINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (inventory_id), FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from inventory table: inventory_id film_id store_id last_update 1 1 1 2006-02-15 05:09:17 2 1 1 2006-02-15 05:09:17 3 1 1 2006-02-15 05:09:17 CREATE TABLE language ( language_id TINYINT UNSIGNED NOT NULL, name CHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (language_id) ) 3 rows from language table: Empty DataFrame Columns: [language_id, name, last_update] Index: [] CREATE TABLE payment ( payment_id SMALLINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, staff_id TINYINT UNSIGNED NOT NULL, rental_id INT DEFAULT NULL, amount DECIMAL(5,2) NOT NULL, payment_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (payment_id), FOREIGN KEY (rental_id) REFERENCES rental (rental_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id) ) 3 rows from payment table: payment_id customer_id staff_id rental_id amount payment_date last_update 1 1 1 76 2.99 2005-05-25 11:30:37 2006-02-15 22:12:30 2 1 1 573 0.99 2005-05-28 10:35:23 2006-02-15 22:12:30 3 1 1 1185 5.99 2005-06-15 00:54:12 2006-02-15 22:12:30 CREATE TABLE rental ( rental_id INT NOT NULL, rental_date DATETIME NOT NULL, inventory_id MEDIUMINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, return_date DATETIME DEFAULT NULL, staff_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (rental_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id), FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id) ) 3 rows from rental table: rental_id rental_date inventory_id customer_id return_date staff_id last_update 1 2005-05-24 22:53:30 367 130 2005-05-26 22:04:30 1 2006-02-15 21:30:53 2 2005-05-24 22:54:33 1525 459 2005-05-28 19:40:33 1 2006-02-15 21:30:53 3 2005-05-24 23:03:39 1711 408 2005-06-01 22:12:39 1 2006-02-15 21:30:53 CREATE TABLE staff ( staff_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, picture BLOB DEFAULT NULL, email VARCHAR(50) DEFAULT NULL, store_id TINYINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, username VARCHAR(16) NOT NULL, password VARCHAR(40) DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (staff_id), --FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from staff table: Empty DataFrame Columns: [staff_id, first_name, last_name, address_id, picture, email, store_id, active, username, password, last_update] Index: [] CREATE TABLE store ( store_id TINYINT UNSIGNED NOT NULL, manager_staff_id TINYINT UNSIGNED NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (store_id), FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from store table: Empty DataFrame Columns: [store_id, manager_staff_id, address_id, last_update] Index: []
sakila_1
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'
CREATE TABLE actor ( actor_id SMALLINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id) ) 3 rows from actor table: actor_id first_name last_name last_update 1 PENELOPE GUINESS 2006-02-15 04:34:33 2 NICK WAHLBERG 2006-02-15 04:34:33 3 ED CHASE 2006-02-15 04:34:33 CREATE TABLE address ( address_id SMALLINT UNSIGNED NOT NULL, address VARCHAR(50) NOT NULL, address2 VARCHAR(50) DEFAULT NULL, district VARCHAR(20) NOT NULL, city_id SMALLINT UNSIGNED NOT NULL, postal_code VARCHAR(10) DEFAULT NULL, phone VARCHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (address_id), FOREIGN KEY (city_id) REFERENCES city (city_id) ) 3 rows from address table: address_id address address2 district city_id postal_code phone last_update 1 47 MySakila Drive None Alberta 300 2006-02-15 04:45:30 2 28 MySQL Boulevard None QLD 576 2006-02-15 04:45:30 3 23 Workhaven Lane None Alberta 300 14033335568 2006-02-15 04:45:30 CREATE TABLE category ( category_id TINYINT UNSIGNED NOT NULL, name VARCHAR(25) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (category_id) ) 3 rows from category table: category_id name last_update 1 Action 2006-02-15 04:46:27 2 Animation 2006-02-15 04:46:27 3 Children 2006-02-15 04:46:27 CREATE TABLE city ( city_id SMALLINT UNSIGNED NOT NULL, city VARCHAR(50) NOT NULL, country_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (city_id), FOREIGN KEY (country_id) REFERENCES country (country_id) ) 3 rows from city table: city_id city country_id last_update 1 A Corua (La Corua) 87 2006-02-15 04:45:25 2 Abha 82 2006-02-15 04:45:25 3 Abu Dhabi 101 2006-02-15 04:45:25 CREATE TABLE country ( country_id SMALLINT UNSIGNED NOT NULL, country VARCHAR(50) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (country_id) ) 3 rows from country table: country_id country last_update 1 Afghanistan 2006-02-15 04:44:00 2 Algeria 2006-02-15 04:44:00 3 American Samoa 2006-02-15 04:44:00 CREATE TABLE customer ( customer_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, email VARCHAR(50) DEFAULT NULL, address_id SMALLINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, create_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (customer_id), FOREIGN KEY (address_id) REFERENCES address (address_id), FOREIGN KEY (store_id) REFERENCES store (store_id) ) 3 rows from customer table: customer_id store_id first_name last_name email address_id active create_date last_update 1 1 MARY SMITH MARY.SMITH@sakilacustomer.org 5 1 2006-02-14 22:04:36 2006-02-15 04:57:20 2 1 PATRICIA JOHNSON PATRICIA.JOHNSON@sakilacustomer.org 6 1 2006-02-14 22:04:36 2006-02-15 04:57:20 3 1 LINDA WILLIAMS LINDA.WILLIAMS@sakilacustomer.org 7 1 2006-02-14 22:04:36 2006-02-15 04:57:20 CREATE TABLE film ( film_id SMALLINT UNSIGNED NOT NULL, title VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, release_year YEAR DEFAULT NULL, language_id TINYINT UNSIGNED NOT NULL, original_language_id TINYINT UNSIGNED DEFAULT NULL, rental_duration TINYINT UNSIGNED NOT NULL DEFAULT 3, rental_rate DECIMAL(4,2) NOT NULL DEFAULT 4.99, length SMALLINT UNSIGNED DEFAULT NULL, replacement_cost DECIMAL(5,2) NOT NULL DEFAULT 19.99, rating DEFAULT 'G', special_features DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id), FOREIGN KEY (language_id) REFERENCES language (language_id), FOREIGN KEY (original_language_id) REFERENCES language (language_id) ) 3 rows from film table: film_id title description release_year language_id original_language_id rental_duration rental_rate length replacement_cost rating special_features last_update 1 ACADEMY DINOSAUR A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies 2006 1 None 6 0.99 86 20.99 PG Deleted Scenes,Behind the Scenes 2006-02-15 05:03:42 2 ACE GOLDFINGER A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China 2006 1 None 3 4.99 48 12.99 G Trailers,Deleted Scenes 2006-02-15 05:03:42 3 ADAPTATION HOLES A Astounding Reflection of a Lumberjack And a Car who must Sink a Lumberjack in A Baloon Factory 2006 1 None 7 2.99 50 18.99 NC-17 Trailers,Deleted Scenes 2006-02-15 05:03:42 CREATE TABLE film_actor ( actor_id SMALLINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id,film_id), FOREIGN KEY (actor_id) REFERENCES actor (actor_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from film_actor table: actor_id film_id last_update 1 1 2006-02-15 05:05:03 1 23 2006-02-15 05:05:03 1 25 2006-02-15 05:05:03 CREATE TABLE film_category ( film_id SMALLINT UNSIGNED NOT NULL, category_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id, category_id), FOREIGN KEY (film_id) REFERENCES film (film_id), FOREIGN KEY (category_id) REFERENCES category (category_id) ) 3 rows from film_category table: film_id category_id last_update 1 6 2006-02-15 05:07:09 2 11 2006-02-15 05:07:09 3 6 2006-02-15 05:07:09 CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ) 3 rows from film_text table: Empty DataFrame Columns: [film_id, title, description] Index: [] CREATE TABLE inventory ( inventory_id MEDIUMINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (inventory_id), FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from inventory table: inventory_id film_id store_id last_update 1 1 1 2006-02-15 05:09:17 2 1 1 2006-02-15 05:09:17 3 1 1 2006-02-15 05:09:17 CREATE TABLE language ( language_id TINYINT UNSIGNED NOT NULL, name CHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (language_id) ) 3 rows from language table: Empty DataFrame Columns: [language_id, name, last_update] Index: [] CREATE TABLE payment ( payment_id SMALLINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, staff_id TINYINT UNSIGNED NOT NULL, rental_id INT DEFAULT NULL, amount DECIMAL(5,2) NOT NULL, payment_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (payment_id), FOREIGN KEY (rental_id) REFERENCES rental (rental_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id) ) 3 rows from payment table: payment_id customer_id staff_id rental_id amount payment_date last_update 1 1 1 76 2.99 2005-05-25 11:30:37 2006-02-15 22:12:30 2 1 1 573 0.99 2005-05-28 10:35:23 2006-02-15 22:12:30 3 1 1 1185 5.99 2005-06-15 00:54:12 2006-02-15 22:12:30 CREATE TABLE rental ( rental_id INT NOT NULL, rental_date DATETIME NOT NULL, inventory_id MEDIUMINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, return_date DATETIME DEFAULT NULL, staff_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (rental_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id), FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id) ) 3 rows from rental table: rental_id rental_date inventory_id customer_id return_date staff_id last_update 1 2005-05-24 22:53:30 367 130 2005-05-26 22:04:30 1 2006-02-15 21:30:53 2 2005-05-24 22:54:33 1525 459 2005-05-28 19:40:33 1 2006-02-15 21:30:53 3 2005-05-24 23:03:39 1711 408 2005-06-01 22:12:39 1 2006-02-15 21:30:53 CREATE TABLE staff ( staff_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, picture BLOB DEFAULT NULL, email VARCHAR(50) DEFAULT NULL, store_id TINYINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, username VARCHAR(16) NOT NULL, password VARCHAR(40) DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (staff_id), --FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from staff table: Empty DataFrame Columns: [staff_id, first_name, last_name, address_id, picture, email, store_id, active, username, password, last_update] Index: [] CREATE TABLE store ( store_id TINYINT UNSIGNED NOT NULL, manager_staff_id TINYINT UNSIGNED NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (store_id), FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from store table: Empty DataFrame Columns: [store_id, manager_staff_id, address_id, last_update] Index: []
sakila_1
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'
CREATE TABLE actor ( actor_id SMALLINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id) ) 3 rows from actor table: actor_id first_name last_name last_update 1 PENELOPE GUINESS 2006-02-15 04:34:33 2 NICK WAHLBERG 2006-02-15 04:34:33 3 ED CHASE 2006-02-15 04:34:33 CREATE TABLE address ( address_id SMALLINT UNSIGNED NOT NULL, address VARCHAR(50) NOT NULL, address2 VARCHAR(50) DEFAULT NULL, district VARCHAR(20) NOT NULL, city_id SMALLINT UNSIGNED NOT NULL, postal_code VARCHAR(10) DEFAULT NULL, phone VARCHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (address_id), FOREIGN KEY (city_id) REFERENCES city (city_id) ) 3 rows from address table: address_id address address2 district city_id postal_code phone last_update 1 47 MySakila Drive None Alberta 300 2006-02-15 04:45:30 2 28 MySQL Boulevard None QLD 576 2006-02-15 04:45:30 3 23 Workhaven Lane None Alberta 300 14033335568 2006-02-15 04:45:30 CREATE TABLE category ( category_id TINYINT UNSIGNED NOT NULL, name VARCHAR(25) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (category_id) ) 3 rows from category table: category_id name last_update 1 Action 2006-02-15 04:46:27 2 Animation 2006-02-15 04:46:27 3 Children 2006-02-15 04:46:27 CREATE TABLE city ( city_id SMALLINT UNSIGNED NOT NULL, city VARCHAR(50) NOT NULL, country_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (city_id), FOREIGN KEY (country_id) REFERENCES country (country_id) ) 3 rows from city table: city_id city country_id last_update 1 A Corua (La Corua) 87 2006-02-15 04:45:25 2 Abha 82 2006-02-15 04:45:25 3 Abu Dhabi 101 2006-02-15 04:45:25 CREATE TABLE country ( country_id SMALLINT UNSIGNED NOT NULL, country VARCHAR(50) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (country_id) ) 3 rows from country table: country_id country last_update 1 Afghanistan 2006-02-15 04:44:00 2 Algeria 2006-02-15 04:44:00 3 American Samoa 2006-02-15 04:44:00 CREATE TABLE customer ( customer_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, email VARCHAR(50) DEFAULT NULL, address_id SMALLINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, create_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (customer_id), FOREIGN KEY (address_id) REFERENCES address (address_id), FOREIGN KEY (store_id) REFERENCES store (store_id) ) 3 rows from customer table: customer_id store_id first_name last_name email address_id active create_date last_update 1 1 MARY SMITH MARY.SMITH@sakilacustomer.org 5 1 2006-02-14 22:04:36 2006-02-15 04:57:20 2 1 PATRICIA JOHNSON PATRICIA.JOHNSON@sakilacustomer.org 6 1 2006-02-14 22:04:36 2006-02-15 04:57:20 3 1 LINDA WILLIAMS LINDA.WILLIAMS@sakilacustomer.org 7 1 2006-02-14 22:04:36 2006-02-15 04:57:20 CREATE TABLE film ( film_id SMALLINT UNSIGNED NOT NULL, title VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, release_year YEAR DEFAULT NULL, language_id TINYINT UNSIGNED NOT NULL, original_language_id TINYINT UNSIGNED DEFAULT NULL, rental_duration TINYINT UNSIGNED NOT NULL DEFAULT 3, rental_rate DECIMAL(4,2) NOT NULL DEFAULT 4.99, length SMALLINT UNSIGNED DEFAULT NULL, replacement_cost DECIMAL(5,2) NOT NULL DEFAULT 19.99, rating DEFAULT 'G', special_features DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id), FOREIGN KEY (language_id) REFERENCES language (language_id), FOREIGN KEY (original_language_id) REFERENCES language (language_id) ) 3 rows from film table: film_id title description release_year language_id original_language_id rental_duration rental_rate length replacement_cost rating special_features last_update 1 ACADEMY DINOSAUR A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies 2006 1 None 6 0.99 86 20.99 PG Deleted Scenes,Behind the Scenes 2006-02-15 05:03:42 2 ACE GOLDFINGER A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China 2006 1 None 3 4.99 48 12.99 G Trailers,Deleted Scenes 2006-02-15 05:03:42 3 ADAPTATION HOLES A Astounding Reflection of a Lumberjack And a Car who must Sink a Lumberjack in A Baloon Factory 2006 1 None 7 2.99 50 18.99 NC-17 Trailers,Deleted Scenes 2006-02-15 05:03:42 CREATE TABLE film_actor ( actor_id SMALLINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id,film_id), FOREIGN KEY (actor_id) REFERENCES actor (actor_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from film_actor table: actor_id film_id last_update 1 1 2006-02-15 05:05:03 1 23 2006-02-15 05:05:03 1 25 2006-02-15 05:05:03 CREATE TABLE film_category ( film_id SMALLINT UNSIGNED NOT NULL, category_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id, category_id), FOREIGN KEY (film_id) REFERENCES film (film_id), FOREIGN KEY (category_id) REFERENCES category (category_id) ) 3 rows from film_category table: film_id category_id last_update 1 6 2006-02-15 05:07:09 2 11 2006-02-15 05:07:09 3 6 2006-02-15 05:07:09 CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ) 3 rows from film_text table: Empty DataFrame Columns: [film_id, title, description] Index: [] CREATE TABLE inventory ( inventory_id MEDIUMINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (inventory_id), FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from inventory table: inventory_id film_id store_id last_update 1 1 1 2006-02-15 05:09:17 2 1 1 2006-02-15 05:09:17 3 1 1 2006-02-15 05:09:17 CREATE TABLE language ( language_id TINYINT UNSIGNED NOT NULL, name CHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (language_id) ) 3 rows from language table: Empty DataFrame Columns: [language_id, name, last_update] Index: [] CREATE TABLE payment ( payment_id SMALLINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, staff_id TINYINT UNSIGNED NOT NULL, rental_id INT DEFAULT NULL, amount DECIMAL(5,2) NOT NULL, payment_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (payment_id), FOREIGN KEY (rental_id) REFERENCES rental (rental_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id) ) 3 rows from payment table: payment_id customer_id staff_id rental_id amount payment_date last_update 1 1 1 76 2.99 2005-05-25 11:30:37 2006-02-15 22:12:30 2 1 1 573 0.99 2005-05-28 10:35:23 2006-02-15 22:12:30 3 1 1 1185 5.99 2005-06-15 00:54:12 2006-02-15 22:12:30 CREATE TABLE rental ( rental_id INT NOT NULL, rental_date DATETIME NOT NULL, inventory_id MEDIUMINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, return_date DATETIME DEFAULT NULL, staff_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (rental_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id), FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id) ) 3 rows from rental table: rental_id rental_date inventory_id customer_id return_date staff_id last_update 1 2005-05-24 22:53:30 367 130 2005-05-26 22:04:30 1 2006-02-15 21:30:53 2 2005-05-24 22:54:33 1525 459 2005-05-28 19:40:33 1 2006-02-15 21:30:53 3 2005-05-24 23:03:39 1711 408 2005-06-01 22:12:39 1 2006-02-15 21:30:53 CREATE TABLE staff ( staff_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, picture BLOB DEFAULT NULL, email VARCHAR(50) DEFAULT NULL, store_id TINYINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, username VARCHAR(16) NOT NULL, password VARCHAR(40) DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (staff_id), --FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from staff table: Empty DataFrame Columns: [staff_id, first_name, last_name, address_id, picture, email, store_id, active, username, password, last_update] Index: [] CREATE TABLE store ( store_id TINYINT UNSIGNED NOT NULL, manager_staff_id TINYINT UNSIGNED NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (store_id), FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from store table: Empty DataFrame Columns: [store_id, manager_staff_id, address_id, last_update] Index: []
sakila_1
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' )
CREATE TABLE actor ( actor_id SMALLINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id) ) 3 rows from actor table: actor_id first_name last_name last_update 1 PENELOPE GUINESS 2006-02-15 04:34:33 2 NICK WAHLBERG 2006-02-15 04:34:33 3 ED CHASE 2006-02-15 04:34:33 CREATE TABLE address ( address_id SMALLINT UNSIGNED NOT NULL, address VARCHAR(50) NOT NULL, address2 VARCHAR(50) DEFAULT NULL, district VARCHAR(20) NOT NULL, city_id SMALLINT UNSIGNED NOT NULL, postal_code VARCHAR(10) DEFAULT NULL, phone VARCHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (address_id), FOREIGN KEY (city_id) REFERENCES city (city_id) ) 3 rows from address table: address_id address address2 district city_id postal_code phone last_update 1 47 MySakila Drive None Alberta 300 2006-02-15 04:45:30 2 28 MySQL Boulevard None QLD 576 2006-02-15 04:45:30 3 23 Workhaven Lane None Alberta 300 14033335568 2006-02-15 04:45:30 CREATE TABLE category ( category_id TINYINT UNSIGNED NOT NULL, name VARCHAR(25) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (category_id) ) 3 rows from category table: category_id name last_update 1 Action 2006-02-15 04:46:27 2 Animation 2006-02-15 04:46:27 3 Children 2006-02-15 04:46:27 CREATE TABLE city ( city_id SMALLINT UNSIGNED NOT NULL, city VARCHAR(50) NOT NULL, country_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (city_id), FOREIGN KEY (country_id) REFERENCES country (country_id) ) 3 rows from city table: city_id city country_id last_update 1 A Corua (La Corua) 87 2006-02-15 04:45:25 2 Abha 82 2006-02-15 04:45:25 3 Abu Dhabi 101 2006-02-15 04:45:25 CREATE TABLE country ( country_id SMALLINT UNSIGNED NOT NULL, country VARCHAR(50) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (country_id) ) 3 rows from country table: country_id country last_update 1 Afghanistan 2006-02-15 04:44:00 2 Algeria 2006-02-15 04:44:00 3 American Samoa 2006-02-15 04:44:00 CREATE TABLE customer ( customer_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, email VARCHAR(50) DEFAULT NULL, address_id SMALLINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, create_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (customer_id), FOREIGN KEY (address_id) REFERENCES address (address_id), FOREIGN KEY (store_id) REFERENCES store (store_id) ) 3 rows from customer table: customer_id store_id first_name last_name email address_id active create_date last_update 1 1 MARY SMITH MARY.SMITH@sakilacustomer.org 5 1 2006-02-14 22:04:36 2006-02-15 04:57:20 2 1 PATRICIA JOHNSON PATRICIA.JOHNSON@sakilacustomer.org 6 1 2006-02-14 22:04:36 2006-02-15 04:57:20 3 1 LINDA WILLIAMS LINDA.WILLIAMS@sakilacustomer.org 7 1 2006-02-14 22:04:36 2006-02-15 04:57:20 CREATE TABLE film ( film_id SMALLINT UNSIGNED NOT NULL, title VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, release_year YEAR DEFAULT NULL, language_id TINYINT UNSIGNED NOT NULL, original_language_id TINYINT UNSIGNED DEFAULT NULL, rental_duration TINYINT UNSIGNED NOT NULL DEFAULT 3, rental_rate DECIMAL(4,2) NOT NULL DEFAULT 4.99, length SMALLINT UNSIGNED DEFAULT NULL, replacement_cost DECIMAL(5,2) NOT NULL DEFAULT 19.99, rating DEFAULT 'G', special_features DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id), FOREIGN KEY (language_id) REFERENCES language (language_id), FOREIGN KEY (original_language_id) REFERENCES language (language_id) ) 3 rows from film table: film_id title description release_year language_id original_language_id rental_duration rental_rate length replacement_cost rating special_features last_update 1 ACADEMY DINOSAUR A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies 2006 1 None 6 0.99 86 20.99 PG Deleted Scenes,Behind the Scenes 2006-02-15 05:03:42 2 ACE GOLDFINGER A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China 2006 1 None 3 4.99 48 12.99 G Trailers,Deleted Scenes 2006-02-15 05:03:42 3 ADAPTATION HOLES A Astounding Reflection of a Lumberjack And a Car who must Sink a Lumberjack in A Baloon Factory 2006 1 None 7 2.99 50 18.99 NC-17 Trailers,Deleted Scenes 2006-02-15 05:03:42 CREATE TABLE film_actor ( actor_id SMALLINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id,film_id), FOREIGN KEY (actor_id) REFERENCES actor (actor_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from film_actor table: actor_id film_id last_update 1 1 2006-02-15 05:05:03 1 23 2006-02-15 05:05:03 1 25 2006-02-15 05:05:03 CREATE TABLE film_category ( film_id SMALLINT UNSIGNED NOT NULL, category_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id, category_id), FOREIGN KEY (film_id) REFERENCES film (film_id), FOREIGN KEY (category_id) REFERENCES category (category_id) ) 3 rows from film_category table: film_id category_id last_update 1 6 2006-02-15 05:07:09 2 11 2006-02-15 05:07:09 3 6 2006-02-15 05:07:09 CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ) 3 rows from film_text table: Empty DataFrame Columns: [film_id, title, description] Index: [] CREATE TABLE inventory ( inventory_id MEDIUMINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (inventory_id), FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from inventory table: inventory_id film_id store_id last_update 1 1 1 2006-02-15 05:09:17 2 1 1 2006-02-15 05:09:17 3 1 1 2006-02-15 05:09:17 CREATE TABLE language ( language_id TINYINT UNSIGNED NOT NULL, name CHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (language_id) ) 3 rows from language table: Empty DataFrame Columns: [language_id, name, last_update] Index: [] CREATE TABLE payment ( payment_id SMALLINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, staff_id TINYINT UNSIGNED NOT NULL, rental_id INT DEFAULT NULL, amount DECIMAL(5,2) NOT NULL, payment_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (payment_id), FOREIGN KEY (rental_id) REFERENCES rental (rental_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id) ) 3 rows from payment table: payment_id customer_id staff_id rental_id amount payment_date last_update 1 1 1 76 2.99 2005-05-25 11:30:37 2006-02-15 22:12:30 2 1 1 573 0.99 2005-05-28 10:35:23 2006-02-15 22:12:30 3 1 1 1185 5.99 2005-06-15 00:54:12 2006-02-15 22:12:30 CREATE TABLE rental ( rental_id INT NOT NULL, rental_date DATETIME NOT NULL, inventory_id MEDIUMINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, return_date DATETIME DEFAULT NULL, staff_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (rental_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id), FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id) ) 3 rows from rental table: rental_id rental_date inventory_id customer_id return_date staff_id last_update 1 2005-05-24 22:53:30 367 130 2005-05-26 22:04:30 1 2006-02-15 21:30:53 2 2005-05-24 22:54:33 1525 459 2005-05-28 19:40:33 1 2006-02-15 21:30:53 3 2005-05-24 23:03:39 1711 408 2005-06-01 22:12:39 1 2006-02-15 21:30:53 CREATE TABLE staff ( staff_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, picture BLOB DEFAULT NULL, email VARCHAR(50) DEFAULT NULL, store_id TINYINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, username VARCHAR(16) NOT NULL, password VARCHAR(40) DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (staff_id), --FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from staff table: Empty DataFrame Columns: [staff_id, first_name, last_name, address_id, picture, email, store_id, active, username, password, last_update] Index: [] CREATE TABLE store ( store_id TINYINT UNSIGNED NOT NULL, manager_staff_id TINYINT UNSIGNED NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (store_id), FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from store table: Empty DataFrame Columns: [store_id, manager_staff_id, address_id, last_update] Index: []
sakila_1
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' )
CREATE TABLE actor ( actor_id SMALLINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id) ) 3 rows from actor table: actor_id first_name last_name last_update 1 PENELOPE GUINESS 2006-02-15 04:34:33 2 NICK WAHLBERG 2006-02-15 04:34:33 3 ED CHASE 2006-02-15 04:34:33 CREATE TABLE address ( address_id SMALLINT UNSIGNED NOT NULL, address VARCHAR(50) NOT NULL, address2 VARCHAR(50) DEFAULT NULL, district VARCHAR(20) NOT NULL, city_id SMALLINT UNSIGNED NOT NULL, postal_code VARCHAR(10) DEFAULT NULL, phone VARCHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (address_id), FOREIGN KEY (city_id) REFERENCES city (city_id) ) 3 rows from address table: address_id address address2 district city_id postal_code phone last_update 1 47 MySakila Drive None Alberta 300 2006-02-15 04:45:30 2 28 MySQL Boulevard None QLD 576 2006-02-15 04:45:30 3 23 Workhaven Lane None Alberta 300 14033335568 2006-02-15 04:45:30 CREATE TABLE category ( category_id TINYINT UNSIGNED NOT NULL, name VARCHAR(25) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (category_id) ) 3 rows from category table: category_id name last_update 1 Action 2006-02-15 04:46:27 2 Animation 2006-02-15 04:46:27 3 Children 2006-02-15 04:46:27 CREATE TABLE city ( city_id SMALLINT UNSIGNED NOT NULL, city VARCHAR(50) NOT NULL, country_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (city_id), FOREIGN KEY (country_id) REFERENCES country (country_id) ) 3 rows from city table: city_id city country_id last_update 1 A Corua (La Corua) 87 2006-02-15 04:45:25 2 Abha 82 2006-02-15 04:45:25 3 Abu Dhabi 101 2006-02-15 04:45:25 CREATE TABLE country ( country_id SMALLINT UNSIGNED NOT NULL, country VARCHAR(50) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (country_id) ) 3 rows from country table: country_id country last_update 1 Afghanistan 2006-02-15 04:44:00 2 Algeria 2006-02-15 04:44:00 3 American Samoa 2006-02-15 04:44:00 CREATE TABLE customer ( customer_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, email VARCHAR(50) DEFAULT NULL, address_id SMALLINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, create_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (customer_id), FOREIGN KEY (address_id) REFERENCES address (address_id), FOREIGN KEY (store_id) REFERENCES store (store_id) ) 3 rows from customer table: customer_id store_id first_name last_name email address_id active create_date last_update 1 1 MARY SMITH MARY.SMITH@sakilacustomer.org 5 1 2006-02-14 22:04:36 2006-02-15 04:57:20 2 1 PATRICIA JOHNSON PATRICIA.JOHNSON@sakilacustomer.org 6 1 2006-02-14 22:04:36 2006-02-15 04:57:20 3 1 LINDA WILLIAMS LINDA.WILLIAMS@sakilacustomer.org 7 1 2006-02-14 22:04:36 2006-02-15 04:57:20 CREATE TABLE film ( film_id SMALLINT UNSIGNED NOT NULL, title VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, release_year YEAR DEFAULT NULL, language_id TINYINT UNSIGNED NOT NULL, original_language_id TINYINT UNSIGNED DEFAULT NULL, rental_duration TINYINT UNSIGNED NOT NULL DEFAULT 3, rental_rate DECIMAL(4,2) NOT NULL DEFAULT 4.99, length SMALLINT UNSIGNED DEFAULT NULL, replacement_cost DECIMAL(5,2) NOT NULL DEFAULT 19.99, rating DEFAULT 'G', special_features DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id), FOREIGN KEY (language_id) REFERENCES language (language_id), FOREIGN KEY (original_language_id) REFERENCES language (language_id) ) 3 rows from film table: film_id title description release_year language_id original_language_id rental_duration rental_rate length replacement_cost rating special_features last_update 1 ACADEMY DINOSAUR A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies 2006 1 None 6 0.99 86 20.99 PG Deleted Scenes,Behind the Scenes 2006-02-15 05:03:42 2 ACE GOLDFINGER A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China 2006 1 None 3 4.99 48 12.99 G Trailers,Deleted Scenes 2006-02-15 05:03:42 3 ADAPTATION HOLES A Astounding Reflection of a Lumberjack And a Car who must Sink a Lumberjack in A Baloon Factory 2006 1 None 7 2.99 50 18.99 NC-17 Trailers,Deleted Scenes 2006-02-15 05:03:42 CREATE TABLE film_actor ( actor_id SMALLINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id,film_id), FOREIGN KEY (actor_id) REFERENCES actor (actor_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from film_actor table: actor_id film_id last_update 1 1 2006-02-15 05:05:03 1 23 2006-02-15 05:05:03 1 25 2006-02-15 05:05:03 CREATE TABLE film_category ( film_id SMALLINT UNSIGNED NOT NULL, category_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (film_id, category_id), FOREIGN KEY (film_id) REFERENCES film (film_id), FOREIGN KEY (category_id) REFERENCES category (category_id) ) 3 rows from film_category table: film_id category_id last_update 1 6 2006-02-15 05:07:09 2 11 2006-02-15 05:07:09 3 6 2006-02-15 05:07:09 CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ) 3 rows from film_text table: Empty DataFrame Columns: [film_id, title, description] Index: [] CREATE TABLE inventory ( inventory_id MEDIUMINT UNSIGNED NOT NULL, film_id SMALLINT UNSIGNED NOT NULL, store_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (inventory_id), FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (film_id) REFERENCES film (film_id) ) 3 rows from inventory table: inventory_id film_id store_id last_update 1 1 1 2006-02-15 05:09:17 2 1 1 2006-02-15 05:09:17 3 1 1 2006-02-15 05:09:17 CREATE TABLE language ( language_id TINYINT UNSIGNED NOT NULL, name CHAR(20) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (language_id) ) 3 rows from language table: Empty DataFrame Columns: [language_id, name, last_update] Index: [] CREATE TABLE payment ( payment_id SMALLINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, staff_id TINYINT UNSIGNED NOT NULL, rental_id INT DEFAULT NULL, amount DECIMAL(5,2) NOT NULL, payment_date DATETIME NOT NULL, last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (payment_id), FOREIGN KEY (rental_id) REFERENCES rental (rental_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id) ) 3 rows from payment table: payment_id customer_id staff_id rental_id amount payment_date last_update 1 1 1 76 2.99 2005-05-25 11:30:37 2006-02-15 22:12:30 2 1 1 573 0.99 2005-05-28 10:35:23 2006-02-15 22:12:30 3 1 1 1185 5.99 2005-06-15 00:54:12 2006-02-15 22:12:30 CREATE TABLE rental ( rental_id INT NOT NULL, rental_date DATETIME NOT NULL, inventory_id MEDIUMINT UNSIGNED NOT NULL, customer_id SMALLINT UNSIGNED NOT NULL, return_date DATETIME DEFAULT NULL, staff_id TINYINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (rental_id), FOREIGN KEY (staff_id) REFERENCES staff (staff_id), FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id), FOREIGN KEY (customer_id) REFERENCES customer (customer_id) ) 3 rows from rental table: rental_id rental_date inventory_id customer_id return_date staff_id last_update 1 2005-05-24 22:53:30 367 130 2005-05-26 22:04:30 1 2006-02-15 21:30:53 2 2005-05-24 22:54:33 1525 459 2005-05-28 19:40:33 1 2006-02-15 21:30:53 3 2005-05-24 23:03:39 1711 408 2005-06-01 22:12:39 1 2006-02-15 21:30:53 CREATE TABLE staff ( staff_id TINYINT UNSIGNED NOT NULL, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, picture BLOB DEFAULT NULL, email VARCHAR(50) DEFAULT NULL, store_id TINYINT UNSIGNED NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, username VARCHAR(16) NOT NULL, password VARCHAR(40) DEFAULT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (staff_id), --FOREIGN KEY (store_id) REFERENCES store (store_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from staff table: Empty DataFrame Columns: [staff_id, first_name, last_name, address_id, picture, email, store_id, active, username, password, last_update] Index: [] CREATE TABLE store ( store_id TINYINT UNSIGNED NOT NULL, manager_staff_id TINYINT UNSIGNED NOT NULL, address_id SMALLINT UNSIGNED NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (store_id), FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id), FOREIGN KEY (address_id) REFERENCES address (address_id) ) 3 rows from store table: Empty DataFrame Columns: [store_id, manager_staff_id, address_id, last_update] Index: []
loan_1
How many bank branches are there?
SELECT count(*) FROM bank
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Count the number of bank branches.
SELECT count(*) FROM bank
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
How many customers are there?
SELECT sum(no_of_customers) FROM bank
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
What is the total number of customers across banks?
SELECT sum(no_of_customers) FROM bank
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Find the number of customers in the banks at New York City.
SELECT sum(no_of_customers) FROM bank WHERE city = 'New York City'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Find the average number of customers in all banks of Utah state.
SELECT avg(no_of_customers) FROM bank WHERE state = 'Utah'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
What is the average number of customers across banks in the state of Utah?
SELECT avg(no_of_customers) FROM bank WHERE state = 'Utah'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Find the average number of customers cross all banks.
SELECT avg(no_of_customers) FROM bank
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
What is the average number of bank customers?
SELECT avg(no_of_customers) FROM bank
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Find the city and state of the bank branch named morningside.
SELECT city , state FROM bank WHERE bname = 'morningside'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
What city and state is the bank with the name morningside in?
SELECT city , state FROM bank WHERE bname = 'morningside'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Find the branch names of banks in the New York state.
SELECT bname FROM bank WHERE state = 'New York'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
What are the names of banks in the state of New York?
SELECT bname FROM bank WHERE state = 'New York'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
List the name of all customers sorted by their account balance in ascending order.
SELECT cust_name FROM customer ORDER BY acc_bal
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
What are the names of all customers, ordered by account balance?
SELECT cust_name FROM customer ORDER BY acc_bal
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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)
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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)
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Find the number of different cities which banks are located at.
SELECT count(DISTINCT city) FROM bank
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
In how many different cities are banks located?
SELECT count(DISTINCT city) FROM bank
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Find the number of different states which banks are located at.
SELECT count(DISTINCT state) FROM bank
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
In how many different states are banks located?
SELECT count(DISTINCT state) FROM bank
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
How many distinct types of accounts are there?
SELECT count(DISTINCT acc_type) FROM customer
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Count the number of different account types.
SELECT count(DISTINCT acc_type) FROM customer
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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%'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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%'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Find the total account balance of each customer from Utah or Texas.
SELECT sum(acc_bal) FROM customer WHERE state = 'Utah' OR state = 'Texas'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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)
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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)
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
Find the name of customer who has the lowest credit score.
SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
What is the name of the customer with the worst credit score?
SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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'
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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)
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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)
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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)
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
loan_1
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)
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)) 3 rows from bank table: branch_ID bname no_of_customers city state 1 morningside 203 New York City New York 2 downtown 123 Salt Lake City Utah 3 broadway 453 New York City New York CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)) 3 rows from customer table: cust_ID cust_name acc_type acc_bal no_of_loans credit_score branch_ID state 1 Mary saving 2000 2 30 2 Utah 2 Jack checking 1000 1 20 1 Texas 3 Owen saving 800000 0 210 3 New York CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID)) 3 rows from loan table: loan_ID loan_type cust_ID branch_ID amount 1 Mortgages 1 1 2050 2 Auto 1 2 3000 3 Business 3 3 5000
behavior_monitoring
How many assessment notes are there in total?
SELECT count(*) FROM ASSESSMENT_NOTES
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What are the dates of the assessment notes?
SELECT date_of_notes FROM Assessment_Notes
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
How many addresses have zip code 197?
SELECT count(*) FROM ADDRESSES WHERE zip_postcode = "197"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
How many distinct incident type codes are there?
SELECT count(DISTINCT incident_type_code) FROM Behavior_Incident
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Return all distinct detention type codes.
SELECT DISTINCT detention_type_code FROM Detention
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
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"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Return all detention summaries.
SELECT detention_summary FROM Detention
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Return the cell phone number and email address for all students.
SELECT cell_mobile_number , email_address FROM STUDENTS
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
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"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
How many distinct students have been in detention?
SELECT count(DISTINCT student_id) FROM Students_in_Detention
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What is the gender of the teacher with last name "Medhurst"?
SELECT gender FROM TEACHERS WHERE last_name = "Medhurst"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
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"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the maximum and minimum monthly rental for all student addresses.
SELECT max(monthly_rental) , min(monthly_rental) FROM Student_Addresses
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the first names of teachers whose email address contains the word "man".
SELECT first_name FROM Teachers WHERE email_address LIKE '%man%'
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11