db_id
stringclasses 127
values | query
stringlengths 20
523
| question
stringlengths 16
224
| schema
stringclasses 127
values |
---|---|---|---|
department_store | SELECT payment_method_code , count(*) FROM customers GROUP BY payment_method_code | How many customers use each payment method? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_id FROM order_items GROUP BY product_id ORDER BY count(*) DESC LIMIT 1 | What is the id of the product that was ordered the most often? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_id FROM order_items GROUP BY product_id ORDER BY count(*) DESC LIMIT 1 | Give the product id for the product that was ordered most frequently. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.customer_name , T1.customer_phone , T1.customer_email FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T2.customer_id ORDER BY count(*) DESC LIMIT 1 | What are the name, phone number and email address of the customer who made the largest number of orders? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.customer_name , T1.customer_phone , T1.customer_email FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T2.customer_id ORDER BY count(*) DESC LIMIT 1 | Return the name, phone number and email address for the customer with the most orders. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_type_code , avg(product_price) FROM products GROUP BY product_type_code | What is the average price for each type of product? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_type_code , avg(product_price) FROM products GROUP BY product_type_code | Return the average price for each product type. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT count(*) FROM department_stores AS T1 JOIN department_store_chain AS T2 ON T1.dept_store_chain_id = T2.dept_store_chain_id WHERE T2.dept_store_chain_name = "South" | How many department stores does the store chain South have? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT count(*) FROM department_stores AS T1 JOIN department_store_chain AS T2 ON T1.dept_store_chain_id = T2.dept_store_chain_id WHERE T2.dept_store_chain_name = "South" | Count the number of stores the chain South has. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.staff_name , T2.job_title_code FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id ORDER BY T2.date_assigned_to DESC LIMIT 1 | What is the name and job title of the staff who was assigned the latest? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.staff_name , T2.job_title_code FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id ORDER BY T2.date_assigned_to DESC LIMIT 1 | Return the name and job title of the staff with the latest date assigned. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T2.product_type_code , T2.product_name , T2.product_price FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id = T2.product_id WHERE T1.supplier_id = 3 | Give me the product type, name and price for all the products supplied by supplier id 3. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T2.product_type_code , T2.product_name , T2.product_price FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id = T2.product_id WHERE T1.supplier_id = 3 | Return the product type, name, and price for products supplied by supplier 3. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending" ORDER BY T2.customer_id | Return the distinct name of customers whose order status is Pending, in the order of customer id. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending" ORDER BY T2.customer_id | What are the distinct names of customers with an order status of Pending, sorted by customer id? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.customer_name , T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "New" INTERSECT SELECT T1.customer_name , T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending" | Find the name and address of the customers who have both New and Pending orders. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.customer_name , T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "New" INTERSECT SELECT T1.customer_name , T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending" | What are the names and addressed of customers who have both New and Pending orders? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.product_id FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id = T2.product_id WHERE T1.supplier_id = 2 AND T2.product_price > (SELECT avg(product_price) FROM products) | Return ids of all the products that are supplied by supplier id 2 and are more expensive than the average price of all products. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.product_id FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id = T2.product_id WHERE T1.supplier_id = 2 AND T2.product_price > (SELECT avg(product_price) FROM products) | What are the ids of products from the supplier with id 2, which are more expensive than the average price across all products? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T2.dept_store_id , T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "marketing" INTERSECT SELECT T2.dept_store_id , T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "managing" | What is the id and name of the department store that has both marketing and managing department? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T2.dept_store_id , T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "marketing" INTERSECT SELECT T2.dept_store_id , T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "managing" | What are the ids and names of department stores with both marketing and managing departments? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT dept_store_chain_id FROM department_stores GROUP BY dept_store_chain_id ORDER BY count(*) DESC LIMIT 2 | What are the ids of the two department store chains with the largest number of department stores? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT dept_store_chain_id FROM department_stores GROUP BY dept_store_chain_id ORDER BY count(*) DESC LIMIT 2 | Return the ids of the two department store chains with the most department stores. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT department_id FROM staff_department_assignments GROUP BY department_id ORDER BY count(*) LIMIT 1 | What is the id of the department with the least number of staff? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT department_id FROM staff_department_assignments GROUP BY department_id ORDER BY count(*) LIMIT 1 | Return the id of the department with the fewest staff assignments. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_type_code , max(product_price) , min(product_price) FROM products GROUP BY product_type_code | For each product type, return the maximum and minimum price. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_type_code , max(product_price) , min(product_price) FROM products GROUP BY product_type_code | What are the maximum and minimum product prices for each product type? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_type_code FROM products GROUP BY product_type_code HAVING avg(product_price) > (SELECT avg(product_price) FROM products) | Find the product type whose average price is higher than the average price of all products. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_type_code FROM products GROUP BY product_type_code HAVING avg(product_price) > (SELECT avg(product_price) FROM products) | What is the code of the product type with an average price higher than the average price of all products? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.staff_id , T1.staff_name FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id ORDER BY date_assigned_to - date_assigned_from LIMIT 1 | Find the id and name of the staff who has been assigned for the shortest period. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.staff_id , T1.staff_name FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id ORDER BY date_assigned_to - date_assigned_from LIMIT 1 | What is the id and name of the staff who has been assigned for the least amount of time? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_name , product_id FROM products WHERE product_price BETWEEN 600 AND 700 | Return the names and ids of all products whose price is between 600 and 700. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_name , product_id FROM products WHERE product_price BETWEEN 600 AND 700 | What are the names and ids of products costing between 600 and 700? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT customer_id FROM Customer_Orders WHERE order_date > (SELECT min(order_date) FROM Customer_Orders WHERE order_status_code = "Cancelled") | Find the ids of all distinct customers who made order after some orders that were Cancelled. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT customer_id FROM Customer_Orders WHERE order_date > (SELECT min(order_date) FROM Customer_Orders WHERE order_status_code = "Cancelled") | What are the distinct ids of customers who made an order after any order that was Cancelled? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to < (SELECT max(date_assigned_to) FROM Staff_Department_Assignments WHERE job_title_code = 'Clerical Staff') | What is id of the staff who had a Staff Department Assignment earlier than any Clerical Staff? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to < (SELECT max(date_assigned_to) FROM Staff_Department_Assignments WHERE job_title_code = 'Clerical Staff') | Return the id of the staff whose Staff Department Assignment was earlier than that of any Clerical Staff. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT customer_name , customer_id FROM customers WHERE customer_address LIKE "%TN%" | What are the names and ids of customers whose address contains TN? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT customer_name , customer_id FROM customers WHERE customer_address LIKE "%TN%" | Return the names and ids of customers who have TN in their address. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.date_assigned_from LIKE "2016%" | Return the name and gender of the staff who was assigned in 2016. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.date_assigned_from LIKE "2016%" | What are the names and genders of staff who were assigned in 2016? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.staff_name FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id GROUP BY T2.staff_id HAVING COUNT (*) > 1 | List the name of staff who has been assigned multiple jobs. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.staff_name FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id GROUP BY T2.staff_id HAVING COUNT (*) > 1 | What are the names of staff who have been assigned multiple jobs? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.supplier_name , T1.supplier_phone FROM Suppliers AS T1 JOIN supplier_addresses AS T2 ON T1.supplier_id = T2.supplier_id JOIN addresses AS T3 ON T2.address_id = T3.address_id ORDER BY T3.address_details | List the name and phone number of all suppliers in the alphabetical order of their addresses. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.supplier_name , T1.supplier_phone FROM Suppliers AS T1 JOIN supplier_addresses AS T2 ON T1.supplier_id = T2.supplier_id JOIN addresses AS T3 ON T2.address_id = T3.address_id ORDER BY T3.address_details | What are the names and phone numbers for all suppliers, sorted in alphabetical order of their addressed? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT customer_phone FROM customers UNION SELECT supplier_phone FROM suppliers | What are the phone numbers of all customers and suppliers. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT customer_phone FROM customers UNION SELECT supplier_phone FROM suppliers | Return the phone numbers for all customers and suppliers. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_id FROM Order_Items GROUP BY product_id HAVING count(*) > 3 UNION SELECT product_id FROM Product_Suppliers GROUP BY product_id HAVING sum(total_amount_purchased) > 80000 | Return the ids of all products that were ordered more than three times or supplied more than 80000. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_id FROM Order_Items GROUP BY product_id HAVING count(*) > 3 UNION SELECT product_id FROM Product_Suppliers GROUP BY product_id HAVING sum(total_amount_purchased) > 80000 | What are the ids of all products that were either ordered more than 3 times or have a cumulative amount purchased of above 80000? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_id , product_name FROM products WHERE product_price < 600 OR product_price > 900 | What are id and name of the products whose price is lower than 600 or higher than 900? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_id , product_name FROM products WHERE product_price < 600 OR product_price > 900 | Give the ids and names of products with price lower than 600 or higher than 900. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id HAVING avg(total_amount_purchased) > 50000 OR avg(total_amount_purchased) < 30000 | Find the id of suppliers whose average amount purchased for each product is above 50000 or below 30000. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id HAVING avg(total_amount_purchased) > 50000 OR avg(total_amount_purchased) < 30000 | What are the ids of suppliers which have an average amount purchased of above 50000 or below 30000? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT avg(total_amount_purchased) , avg(total_value_purchased) FROM Product_Suppliers WHERE supplier_id = (SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id ORDER BY count(*) DESC LIMIT 1) | What are the average amount purchased and value purchased for the supplier who supplies the most products. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT avg(total_amount_purchased) , avg(total_value_purchased) FROM Product_Suppliers WHERE supplier_id = (SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id ORDER BY count(*) DESC LIMIT 1) | Return the average total amount purchased and total value purchased for the supplier who supplies the greatest number of products. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT max(customer_code) , min(customer_code) FROM Customers | What is the largest and smallest customer codes? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT max(customer_code) , min(customer_code) FROM Customers | Return the maximum and minimum customer codes. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id JOIN order_items AS T3 ON T2.order_id = T3.order_id JOIN products AS T4 ON T3.product_id = T4.product_id WHERE T4.product_name = "keyboard" | List the names of all the distinct customers who bought a keyboard. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id JOIN order_items AS T3 ON T2.order_id = T3.order_id JOIN products AS T4 ON T3.product_id = T4.product_id WHERE T4.product_name = "keyboard" | What are the distinct names of customers who have purchased a keyboard? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT T1.supplier_name , T1.supplier_phone FROM suppliers AS T1 JOIN product_suppliers AS T2 ON T1.supplier_id = T2.supplier_id JOIN products AS T3 ON T2.product_id = T3.product_id WHERE T3.product_name = "red jeans" | List the names and phone numbers of all the distinct suppliers who supply red jeans. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT T1.supplier_name , T1.supplier_phone FROM suppliers AS T1 JOIN product_suppliers AS T2 ON T1.supplier_id = T2.supplier_id JOIN products AS T3 ON T2.product_id = T3.product_id WHERE T3.product_name = "red jeans" | What are the distinct names and phone numbers for suppliers who have red jeans? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT max(product_price) , min(product_price) , product_type_code FROM products GROUP BY product_type_code ORDER BY product_type_code | What are the highest and lowest prices of products, grouped by and alphabetically ordered by product type? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT max(product_price) , min(product_price) , product_type_code FROM products GROUP BY product_type_code ORDER BY product_type_code | Give the maximum and minimum product prices for each product type, grouped and ordered by product type. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT order_id , customer_id FROM customer_orders WHERE order_status_code = "Cancelled" ORDER BY order_date | List the order id, customer id for orders in Cancelled status, ordered by their order dates. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT order_id , customer_id FROM customer_orders WHERE order_status_code = "Cancelled" ORDER BY order_date | What are the order ids and customer ids for orders that have been Cancelled, sorted by their order dates? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT T3.product_name FROM customer_orders AS T1 JOIN order_items AS T2 ON T1.order_id = T2.order_id JOIN products AS T3 ON T2.product_id = T3.product_id GROUP BY T3.product_id HAVING COUNT (DISTINCT T1.customer_id) >= 2 | Find the names of products that were bought by at least two distinct customers. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT T3.product_name FROM customer_orders AS T1 JOIN order_items AS T2 ON T1.order_id = T2.order_id JOIN products AS T3 ON T2.product_id = T3.product_id GROUP BY T3.product_id HAVING COUNT (DISTINCT T1.customer_id) >= 2 | What are the distinct names of products purchased by at least two different customers? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id JOIN order_items AS T3 ON T2.order_id = T3.order_id GROUP BY T1.customer_id HAVING COUNT (DISTINCT T3.product_id) >= 3 | Find the names of customers who have bought by at least three distinct products. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id JOIN order_items AS T3 ON T2.order_id = T3.order_id GROUP BY T1.customer_id HAVING COUNT (DISTINCT T3.product_id) >= 3 | What are the distinct names of customers who have purchased at least three different products? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Sales Person" EXCEPT SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Clerical Staff" | Find the name and gender of the staff who has been assigned the job of Sales Person but never Clerical Staff. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Sales Person" EXCEPT SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Clerical Staff" | What are the names and genders of staff who have held the title Sales Person, but never Clerical Staff? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT customer_id , customer_name FROM customers WHERE customer_address LIKE "%WY%" AND payment_method_code != "Credit Card" | Find the id and name of customers whose address contains WY state and do not use credit card for payment. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT customer_id , customer_name FROM customers WHERE customer_address LIKE "%WY%" AND payment_method_code != "Credit Card" | What are the ids and names of customers with addressed that contain WY and who do not use a credit card for payment? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT avg(product_price) FROM products WHERE product_type_code = 'Clothes' | Find the average price of all product clothes. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT avg(product_price) FROM products WHERE product_type_code = 'Clothes' | What is the average price of clothes? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_name FROM products WHERE product_type_code = 'Hardware' ORDER BY product_price DESC LIMIT 1 | Find the name of the most expensive hardware product. | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
department_store | SELECT product_name FROM products WHERE product_type_code = 'Hardware' ORDER BY product_price DESC LIMIT 1 | What is the name of the hardware product with the greatest price? | PRAGMA foreign_keys = ON;
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
);
East Burdettestad, IA 21232');
Port Abefurt, IA 84402-4249');
West Lindsey, DE 76199-8015');
Marvinburgh, OH 16085-1623');
Jenkinsmouth, OK 22345');
Port Isaac, NV 61159');
Langworthborough, OH 95195');
New Cali, RI 42319');
Lake Zariaburgh, IL 98085');
Pourosfurt, IA 98649');
Mooreside, ME 41586-5022');
Wilkinsonstad, CO 79055-7622');
East Rheaview, ID 47493');
Willmsport, NV 36680');
Reingerland, HI 97099-1005');
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
);
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
);
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
);
South Norrisland, SC 80546', '254-072-4068x33935', '[email protected]');
East Dasiabury, IL 72656-3552', '+41(8)1897032009', '[email protected]');
Lake Annalise, TN 35791-8871', '197-417-3557', '[email protected]');
East Cathryn, WY 30751-4404', '+08(3)8056580281', '[email protected]');
East Chris, NH 41624', '1-064-498-6609x051', '[email protected]');
South Dionbury, NC 62021', '(443)013-3112x528', '[email protected]');
Schneiderland, IA 93624', '877-150-8674x63517', '[email protected]');
Coymouth, IL 97300-7731', '1-695-364-7586x59256', '[email protected]');
Lake Moriahbury, OH 91556-2122', '587.398.2400x31176', '[email protected]');
Lizethtown, DE 56522', '857-844-9339x40140', '[email protected]');
New Mckenna, CA 98525-5674', '(730)934-8249', '[email protected]');
Port Zita, SD 39410', '117.822.3577', '[email protected]');
Yesseniaville, TN 60847', '08023680831', '[email protected]');
Darrionborough, SC 53915-0479', '07594320656', '[email protected]');
Wyatttown, UT 12697', '1-472-036-0434', '[email protected]');
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
);
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
);
North Arielle, MS 51249', '(948)944-5099x2027', '[email protected]');
O''Connellshire, IL 31732', '877-917-5029', '[email protected]');
North Wadeton, WV 27575-3951', '1-216-312-0375', '[email protected]');
Mitchellton, TN 84209', '670-466-6367', '[email protected]');
Sporermouth, MN 25962', '01399327266', '[email protected]');
Ninamouth, WA 86667', '1-859-843-1957', '[email protected]');
New Eviestad, NY 17573', '1-109-872-9142x77078', '[email protected]');
West Zacheryshire, NC 17408', '+67(5)4983519062', '[email protected]');
Devonton, NJ 61782-9006', '(723)503-7086x356', '[email protected]');
Strosinville, VA 03998-3292', '07126036440', '[email protected]');
South Jeremiehaven, GA 08730', '611-037-9309', '[email protected]');
North Ginahaven, CT 85046', '(626)763-7031', '[email protected]');
West Dulceside, UT 58085-8998', '1-764-126-7567x0795', '[email protected]');
North Garettton, AL 84756-4375', '319.331.3397', '[email protected]');
Wehnermouth, NC 76791', '(587)993-3604x3077', '[email protected]');
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
);
INSERT INTO Addresses (`address_id`, `address_details`) VALUES (1, '28481 Crist Circle
INSERT INTO Staff (`staff_id`, `staff_gender`, `staff_name`) VALUES (1, '1', 'Tom')INSERT INTO Suppliers (`supplier_id`, `supplier_name`, `supplier_phone`) VALUES (1, 'Lidl', '(692)INSERT INTO Department_Store_Chain (`dept_store_chain_id`, `dept_store_chain_name`) VALUES (1, 'South')INSERT INTO Customers (`customer_id`, `payment_method_code`, `customer_code`, `customer_name`, `customer_address`, `customer_phone`, `customer_email`) VALUES (1, 'Credit Card', '401', 'Ahmed', '75099 Tremblay Port Apt. 163
INSERT INTO Products (`product_id`, `product_type_code`, `product_name`, `product_price`) VALUES (1, 'Clothes', 'red jeans', '734.7300')INSERT INTO Supplier_Addresses (`supplier_id`, `address_id`, `date_from`, `date_to`) VALUES (4, 5, '2016-09-22 16:41:31', '2018-03-14 20:06:37')INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_from`, `date_to`) VALUES (2, 9, '2017-12-11 05:00:22', '2018-03-20 20:52:34')INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status_code`, `order_date`) VALUES (1, 12, 'Completed', '2018-02-10 15:44:48')INSERT INTO Department_Stores (`dept_store_id`, `dept_store_chain_id`, `store_name`, `store_address`, `store_phone`, `store_email`) VALUES (1, 1, 'store_name', '01290 Jeremie Parkway Suite 753
INSERT INTO Departments (`department_id`, `dept_store_id`, `department_name`) VALUES (1, 5, 'human resource')INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`) VALUES (1, 9, 7)INSERT INTO Product_Suppliers (`product_id`, `supplier_id`, `date_supplied_from`, `date_supplied_to`, `total_amount_purchased`, `total_value_purchased`) VALUES (4, 3, '2017-06-19 00:49:05', '2018-03-24 19:29:18', '89366.05', '36014.6000')INSERT INTO Staff_Department_Assignments (`staff_id`, `department_id`, `date_assigned_from`, `job_title_code`, `date_assigned_to`) VALUES (5, 4, '2017-06-11 22:55:20', 'Department Manager', '2018-03-23 21:59:11') |
aircraft | SELECT count(*) FROM aircraft | How many aircrafts are there? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT count(*) FROM aircraft | What is the number of aircraft? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT Description FROM aircraft | List the description of all aircrafts. |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT Description FROM aircraft | What are the descriptions for the aircrafts? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT avg(International_Passengers) FROM airport | What is the average number of international passengers of all airports? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT avg(International_Passengers) FROM airport | What is the average number of international passengers for an airport? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT International_Passengers , Domestic_Passengers FROM airport WHERE Airport_Name = "London Heathrow" | What are the number of international and domestic passengers of the airport named London "Heathrow"? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT International_Passengers , Domestic_Passengers FROM airport WHERE Airport_Name = "London Heathrow" | How many international and domestic passengers are there in the airport London Heathrow? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT sum(Domestic_Passengers) FROM airport WHERE Airport_Name LIKE "%London%" | What are the total number of Domestic Passengers of airports that contain the word "London". |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT sum(Domestic_Passengers) FROM airport WHERE Airport_Name LIKE "%London%" | What are the total number of domestic passengers at all London airports? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT max(Transit_Passengers) , min(Transit_Passengers) FROM airport | What are the maximum and minimum number of transit passengers of all aiports. |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT max(Transit_Passengers) , min(Transit_Passengers) FROM airport | What is the maximum and mininum number of transit passengers for all airports? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT Name FROM pilot WHERE Age >= 25 | What are the name of pilots aged 25 or older? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT Name FROM pilot WHERE Age >= 25 | what is the name of every pilot who is at least 25 years old? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT Name FROM pilot ORDER BY Name ASC | List all pilot names in ascending alphabetical order. |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT Name FROM pilot ORDER BY Name ASC | What are the names of the pilots in alphabetical order? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT Name FROM pilot WHERE Age <= 30 ORDER BY Name DESC | List names of all pilot aged 30 or younger in descending alphabetical order. |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT Name FROM pilot WHERE Age <= 30 ORDER BY Name DESC | What are the names of all pilots 30 years old or young in descending alphabetical order? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT T1.Aircraft FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Airport_Name = "London Gatwick" | Please show the names of aircrafts associated with airport with name "London Gatwick". |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT T1.Aircraft FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Airport_Name = "London Gatwick" | What are the names of all the aircrafts associated with London Gatwick airport? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT T1.Aircraft , T1.Description FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Total_Passengers > 10000000 | Please show the names and descriptions of aircrafts associated with airports that have a total number of passengers bigger than 10000000. |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT T1.Aircraft , T1.Description FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Total_Passengers > 10000000 | What are the names and descriptions of aircrafts associated with an airport that has more total passengers than 10000000? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
aircraft | SELECT avg(T3.Total_Passengers) FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T1.Aircraft = "Robinson R-22" | What is the average total number of passengers of airports that are associated with aircraft "Robinson R-22"? |
PRAGMA foreign_keys = ON;
CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
);
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
);
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
);
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
);
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
);
INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1);
INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054");
INSERT INTO "airport_aircraft" VALUES (1,6,5);
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.