db_id
stringclasses
127 values
query
stringlengths
20
523
question
stringlengths
16
224
schema
stringclasses
127 values
sakila_1
SELECT payment_date FROM payment ORDER BY payment_date ASC LIMIT 1
When did the first payment happen?
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT payment_date FROM payment ORDER BY payment_date ASC LIMIT 1
What was the date of the earliest payment?
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT T2.address , T1.email FROM customer AS T1 JOIN address AS T2 ON T2.address_id = T1.address_id WHERE T1.first_name = 'LINDA'
Where does the customer with the first name Linda live? And what is her email?
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT T2.address , T1.email FROM customer AS T1 JOIN address AS T2 ON T2.address_id = T1.address_id WHERE T1.first_name = 'LINDA'
Return the address and email of the customer with the first name Linda.
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT title FROM film WHERE LENGTH > 100 OR rating = 'PG' EXCEPT SELECT title FROM film WHERE replacement_cost > 200
Find all the films longer than 100 minutes, or rated PG, except those who cost more than 200 for replacement. List the titles.
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT title FROM film WHERE LENGTH > 100 OR rating = 'PG' EXCEPT SELECT title FROM film WHERE replacement_cost > 200
What are the titles of films that are either longer than 100 minutes or rated PG other than those that cost more than 200 to replace?
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT T1.first_name , T1.last_name FROM customer AS T1 JOIN rental AS T2 ON T1.customer_id = T2.customer_id ORDER BY T2.rental_date ASC LIMIT 1
What is the first name and the last name of the customer who made the earliest rental?
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT T1.first_name , T1.last_name FROM customer AS T1 JOIN rental AS T2 ON T1.customer_id = T2.customer_id ORDER BY T2.rental_date ASC LIMIT 1
Return the full name of the customer who made the first rental.
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT DISTINCT T1.first_name , T1.last_name FROM staff AS T1 JOIN rental AS T2 ON T1.staff_id = T2.staff_id JOIN customer AS T3 ON T2.customer_id = T3.customer_id WHERE T3.first_name = 'APRIL' AND T3.last_name = 'BURNS'
What is the full name of the staff member who has rented a film to a customer with the first name April and the last name Burns?
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT DISTINCT T1.first_name , T1.last_name FROM staff AS T1 JOIN rental AS T2 ON T1.staff_id = T2.staff_id JOIN customer AS T3 ON T2.customer_id = T3.customer_id WHERE T3.first_name = 'APRIL' AND T3.last_name = 'BURNS'
Return the full name of the staff who provided a customer with the first name April and the last name Burns with a film rental.
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT store_id FROM customer GROUP BY store_id ORDER BY count(*) DESC LIMIT 1
Which store has most the customers?
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT store_id FROM customer GROUP BY store_id ORDER BY count(*) DESC LIMIT 1
Return the id of the store with the most customers.
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT amount FROM payment ORDER BY amount DESC LIMIT 1
What is the largest payment amount?
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT amount FROM payment ORDER BY amount DESC LIMIT 1
Return the amount of the largest payment.
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT T2.address FROM staff AS T1 JOIN address AS T2 ON T1.address_id = T2.address_id WHERE T1.first_name = 'Elsa'
Where does the staff member with the first name Elsa live?
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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT T2.address FROM staff AS T1 JOIN address AS T2 ON T1.address_id = T2.address_id WHERE T1.first_name = 'Elsa'
Give the address of the staff member who has the 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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT first_name FROM customer WHERE customer_id NOT IN( SELECT customer_id FROM rental WHERE rental_date > '2005-08-23 02:06:01' )
What are the first names of customers who have not rented any films after '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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
sakila_1
SELECT first_name FROM customer WHERE customer_id NOT IN( SELECT customer_id FROM rental WHERE rental_date > '2005-08-23 02:06:01' )
Return the first names of customers who did not rented a film after the 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) ); 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) ); 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) ); 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) ); 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) ); 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, 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) ); 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) ); 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) ); 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) ); CREATE TABLE film_text ( film_id SMALLINT NOT NULL, title VARCHAR(255) NOT NULL, description TEXT, PRIMARY KEY (film_id) ); 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) ); 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) ); 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) ); 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) ); 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) ); 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) ); INSERT INTO actor VALUES (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'),(4,'JENNIFER','DAVIS','2006-02-15 04:34:33'),(5,'JOHNNY','LOLLOBRIGIDA','2006-02-15 04:34:33') INSERT INTO address VALUES (1,'47 MySakila Drive',NULL,'Alberta',300,'','','2006-02-15 04:45:30'),(2,'28 MySQL Boulevard',NULL,'QLD',576,'','','2006-02-15 04:45:30'),(3,'23 Workhaven Lane',NULL,'Alberta',300,'','14033335568','2006-02-15 04:45:30'),(4,'1411 Lillydale Drive',NULL,'QLD',576,'','6172235589','2006-02-15 04:45:30'),(5,'1913 Hanoi Way','','Nagasaki',463,'35200','28303384290','2006-02-15 04:45:30') INSERT INTO category VALUES (1,'Action','2006-02-15 04:46:27'),(2,'Animation','2006-02-15 04:46:27'),(3,'Children','2006-02-15 04:46:27'),(4,'Classics','2006-02-15 04:46:27'),(5,'Comedy','2006-02-15 04:46:27') INSERT INTO city VALUES (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'),(4,'Acua',60,'2006-02-15 04:45:25') INSERT INTO country VALUES (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'),(4,'Angola','2006-02-15 04:44:00'),(5,'Anguilla','2006-02-15 04:44:00') INSERT INTO customer VALUES (1,1,'MARY','SMITH','[email protected]',5,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(2,1,'PATRICIA','JOHNSON','[email protected]',6,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(3,1,'LINDA','WILLIAMS','[email protected]',7,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(4,2,'BARBARA','JONES','[email protected]',8,1,'2006-02-14 22:04:36','2006-02-15 04:57:20'),(5,1,'ELIZABETH','BROWN','[email protected]',9,1,'2006-02-14 22:04:36','2006-02-15 04:57:20') INSERT INTO film VALUES (1,'ACADEMY DINOSAUR','A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',2006,1,NULL,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,NULL,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,NULL,7,'2.99',50,'18.99','NC-17','Trailers,Deleted Scenes','2006-02-15 05:03:42'),(4,'AFFAIR PREJUDICE','A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',2006,1,NULL,5,'2.99',117,'26.99','G','Commentaries,Behind the Scenes','2006-02-15 05:03:42'),(5,'AFRICAN EGG','A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',2006,1,NULL,6,'2.99',130,'22.99','G','Deleted Scenes','2006-02-15 05:03:42') INSERT INTO film_actor VALUES (1,1,'2006-02-15 05:05:03'),(1,23,'2006-02-15 05:05:03'),(1,25,'2006-02-15 05:05:03'),(1,106,'2006-02-15 05:05:03'),(1,140,'2006-02-15 05:05:03') INSERT INTO film_category VALUES (1,6,'2006-02-15 05:07:09'),(2,11,'2006-02-15 05:07:09'),(3,6,'2006-02-15 05:07:09'),(4,11,'2006-02-15 05:07:09'),(5,8,'2006-02-15 05:07:09') INSERT INTO inventory VALUES (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'),(4,1,1,'2006-02-15 05:09:17'),(5,1,2,'2006-02-15 05:09:17') INSERT INTO payment VALUES (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'),(4,1,2,1422,'0.99','2005-06-15 18:02:53','2006-02-15 22:12:30'),(5,1,2,1476,'9.99','2005-06-15 21:08:46','2006-02-15 22:12:30') INSERT INTO rental VALUES (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'),(4,'2005-05-24 23:04:41',2452,333,'2005-06-03 01:43:41',2,'2006-02-15 21:30:53'),(5,'2005-05-24 23:05:21',2079,222,'2005-06-02 04:33:21',1,'2006-02-15 21:30:53')
loan_1
SELECT count(*) FROM bank
How many bank branches are there?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT count(*) FROM bank
Count the number of bank branches.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(no_of_customers) FROM bank
How many customers are there?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(no_of_customers) FROM bank
What is the total number of customers across banks?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(no_of_customers) FROM bank WHERE city = 'New York City'
Find the number of customers in the banks at New York City.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(no_of_customers) FROM bank WHERE city = 'New York City'
What is the total number of customers who use banks in New York City?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT avg(no_of_customers) FROM bank WHERE state = 'Utah'
Find the average number of customers in all banks of Utah state.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT avg(no_of_customers) FROM bank WHERE state = 'Utah'
What is the average number of customers across banks in the state of Utah?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT avg(no_of_customers) FROM bank
Find the average number of customers cross all banks.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT avg(no_of_customers) FROM bank
What is the average number of bank customers?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT city , state FROM bank WHERE bname = 'morningside'
Find the city and state of the bank branch named morningside.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT city , state FROM bank WHERE bname = 'morningside'
What city and state is the bank with the name morningside in?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT bname FROM bank WHERE state = 'New York'
Find the branch names of banks in the New York state.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT bname FROM bank WHERE state = 'New York'
What are the names of banks in the state of New York?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name FROM customer ORDER BY acc_bal
List the name of all customers sorted by their account balance in ascending order.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name FROM customer ORDER BY acc_bal
What are the names of all customers, ordered by account balance?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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)
List the name of all different customers who have some loan sorted by their total loan amount.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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)
What are the names of the different customers who have taken out a loan, ordered by the total amount that they have taken?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT state , acc_type , credit_score FROM customer WHERE no_of_loans = 0
Find the state, account type, and credit score of the customer whose number of loan is 0.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT state , acc_type , credit_score FROM customer WHERE no_of_loans = 0
What are the states, account types, and credit scores for customers who have 0 loans?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT count(DISTINCT city) FROM bank
Find the number of different cities which banks are located at.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT count(DISTINCT city) FROM bank
In how many different cities are banks located?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT count(DISTINCT state) FROM bank
Find the number of different states which banks are located at.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT count(DISTINCT state) FROM bank
In how many different states are banks located?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT count(DISTINCT acc_type) FROM customer
How many distinct types of accounts are there?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT count(DISTINCT acc_type) FROM customer
Count the number of different account types.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name , acc_bal FROM customer WHERE cust_name LIKE '%a%'
Find the name and account balance of the customer whose name includes the letter ‘a’.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name , acc_bal FROM customer WHERE cust_name LIKE '%a%'
What are the names and account balances of customers with the letter a in their names?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(acc_bal) FROM customer WHERE state = 'Utah' OR state = 'Texas'
Find the total account balance of each customer from Utah or Texas.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(acc_bal) FROM customer WHERE state = 'Utah' OR state = 'Texas'
What are the total account balances for each customer from Utah or Texas?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name FROM customer WHERE acc_type = 'saving' INTERSECT SELECT cust_name FROM customer WHERE acc_type = 'checking'
Find the name of customers who have both saving and checking account types.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name FROM customer WHERE acc_type = 'saving' INTERSECT SELECT cust_name FROM customer WHERE acc_type = 'checking'
What are the names of customers who have both savings and checking accounts?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name FROM customer EXCEPT SELECT cust_name FROM customer WHERE acc_type = 'saving'
Find the name of customers who do not have an saving account.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name FROM customer EXCEPT SELECT cust_name FROM customer WHERE acc_type = 'saving'
What are the names of customers who do not have saving accounts?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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'
Find the name of customers who do not have a loan with a type of Mortgages.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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'
What are the names of customers who have not taken a Mortage loan?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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'
Find the name of customers who have loans of both Mortgages and Auto.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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'
What are the names of customers who have taken both Mortgage and Auto loans?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name FROM customer WHERE credit_score < (SELECT avg(credit_score) FROM customer)
Find the name of customers whose credit score is below the average credit scores of all customers.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name FROM customer WHERE credit_score < (SELECT avg(credit_score) FROM customer)
What are the names of customers with credit score less than the average credit score across customers?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT bname FROM bank ORDER BY no_of_customers DESC LIMIT 1
Find the branch name of the bank that has the most number of customers.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT bname FROM bank ORDER BY no_of_customers DESC LIMIT 1
What is the name of the bank branch with the greatest number of customers?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1
Find the name of customer who has the lowest credit score.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1
What is the name of the customer with the worst credit score?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name , acc_type , acc_bal FROM customer ORDER BY credit_score DESC LIMIT 1
Find the name, account type, and account balance of the customer who has the highest credit score.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT cust_name , acc_type , acc_bal FROM customer ORDER BY credit_score DESC LIMIT 1
What is the name, account type, and account balance corresponding to the customer with the highest credit score?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
Find the name of customer who has the highest amount of loans.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
What is the name of the customer who has greatest total loan amount?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT state FROM bank GROUP BY state ORDER BY sum(no_of_customers) DESC LIMIT 1
Find the state which has the most number of customers.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT state FROM bank GROUP BY state ORDER BY sum(no_of_customers) DESC LIMIT 1
Which state has the greatest total number of bank customers?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT avg(acc_bal) , acc_type FROM customer WHERE credit_score < 50 GROUP BY acc_type
For each account type, find the average account balance of customers with credit score lower than 50.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT avg(acc_bal) , acc_type FROM customer WHERE credit_score < 50 GROUP BY acc_type
What is the average account balance of customers with credit score below 50 for the different account types?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(acc_bal) , state FROM customer WHERE credit_score > 100 GROUP BY state
For each state, find the total account balance of customers whose credit score is above 100.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(acc_bal) , state FROM customer WHERE credit_score > 100 GROUP BY state
What is the total account balance for customers with a credit score of above 100 for the different states?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(amount) , T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname
Find the total amount of loans offered by each bank branch.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(amount) , T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname
What are the names of the different bank branches, and what are their total loan amounts?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
Find the name of customers who have more than one loan.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
What are the names of customers who have taken out more than one loan?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
Find the name and account balance of the customers who have loans with a total amount of more than 5000.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
What are the names and account balances for customers who have taken a total amount of more than 5000 in loans?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
Find the name of bank branch that provided the greatest total amount of loans.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
What is the name of the bank branch that has lent the greatest amount?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
Find the name of bank branch that provided the greatest total amount of loans to customers with credit score is less than 100.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
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?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT DISTINCT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id
Find the name of bank branches that provided some loans.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT DISTINCT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id
What are the names of the different banks that have provided loans?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT DISTINCT T1.cust_name , T1.credit_score FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id
Find the name and credit score of the customers who have some loans.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT DISTINCT T1.cust_name , T1.credit_score FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id
What are the different names and credit scores of customers who have taken a loan?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE amount > 3000
Find the the name of the customers who have a loan with amount more than 3000.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE amount > 3000
What are the names of customers who have a loan of more than 3000 in amount?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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'
Find the city and name of bank branches that provide business loans.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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'
What are the names and cities of bank branches that offer loans for business?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
Find the names of bank branches that have provided a loan to any customer whose credit score is below 100.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
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
What are the names of banks that have loaned money to customers with credit scores below 100?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(T2.amount) FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T1.state = 'New York'
Find the total amount of loans provided by bank branches in the state of New York.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT sum(T2.amount) FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T1.state = 'New York'
What is the total amount of money loaned by banks in New York state?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT avg(credit_score) FROM customer WHERE cust_id IN (SELECT cust_id FROM loan)
Find the average credit score of the customers who have some loan.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT avg(credit_score) FROM customer WHERE cust_id IN (SELECT cust_id FROM loan)
What is the average credit score for customers who have taken a loan?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT avg(credit_score) FROM customer WHERE cust_id NOT IN (SELECT cust_id FROM loan)
Find the average credit score of the customers who do not have any loan.
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
loan_1
SELECT avg(credit_score) FROM customer WHERE cust_id NOT IN (SELECT cust_id FROM loan)
What is the average credit score for customers who have never taken a loan?
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); 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)); 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)); INSERT into bank values (1, 'morningside', 203, 'New York City', 'New York'); INSERT into customer values (1, 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'); INSERT into loan values (1, 'Mortgages', 1, 1, 2050); INSERT INTO bank VALUES [(1, 'morningside', 203, 'New York City', 'New York'), (2, 'downtown', 123, 'Salt Lake City', 'Utah')] INSERT INTO customer VALUES [('1', 'Mary', 'saving', 2000, 2, 30, 2, 'Utah'), ('2', 'Jack', 'checking', 1000, 1, 20, 1, 'Texas')] INSERT INTO loan VALUES [('1', 'Mortgages', '1', '1', 2050), ('2', 'Auto', '1', '2', 3000)]
behavior_monitoring
SELECT count(*) FROM ASSESSMENT_NOTES
How many assessment notes are there in total?
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); 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) ); 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` ) ); 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` ) ); 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` ) ); 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` ) ); 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` ) ); 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` ) ); 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` ) ); INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing'); INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time'); INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise'); INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL); INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL); INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL); INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL); INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL); INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL); INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house'); INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1);
behavior_monitoring
SELECT date_of_notes FROM Assessment_Notes
What are the dates of the assessment notes?
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); 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) ); 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` ) ); 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` ) ); 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` ) ); 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` ) ); 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` ) ); 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` ) ); 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` ) ); INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing'); INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time'); INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise'); INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL); INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL); INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL); INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL); INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL); INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL); INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house'); INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1);