db_id
stringclasses
127 values
query
stringlengths
20
523
question
stringlengths
16
224
schema
stringclasses
127 values
activity_1
SELECT T1.stuid FROM participates_in AS T1 JOIN activity AS T2 ON T2.actid = T2.actid WHERE T2.activity_name = 'Canoeing' INTERSECT SELECT T1.stuid FROM participates_in AS T1 JOIN activity AS T2 ON T2.actid = T2.actid WHERE T2.activity_name = 'Kayaking'
Which students participate in both Canoeing and Kayaking as their activities? Tell me their student ids.
create table Activity ( actid INTEGER PRIMARY KEY, activity_name varchar(25) ); create table Participates_in ( stuid INTEGER, actid INTEGER, FOREIGN KEY(stuid) REFERENCES Student(StuID), FOREIGN KEY(actid) REFERENCES Activity(actid) ); create table Faculty_Participates_in ( FacID INTEGER, actid INTEGER, FOREIGN KEY(FacID) REFERENCES Faculty(FacID), FOREIGN KEY(actid) REFERENCES Activity(actid) ); create table Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ); create table Faculty ( FacID INTEGER PRIMARY KEY, Lname VARCHAR(15), Fname VARCHAR(15), Rank VARCHAR(15), Sex VARCHAR(1), Phone INTEGER, Room VARCHAR(5), Building VARCHAR(13) ); insert into Faculty values ( 1082, 'Giuliano', 'Mark', 'Instructor', 'M', 2424, '224', 'NEB'); insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL'); insert into Activity values ( 770 , 'Mountain Climbing' ) ; insert into Participates_in values (1001 , 770) ; insert into Faculty_Participates_in values ( 1082, 784) ; INSERT INTO Activity VALUES [(770, 'Mountain Climbing'), (771, 'Canoeing')] INSERT INTO Participates_in VALUES [(1001, 770), (1001, 771)] INSERT INTO Faculty_Participates_in VALUES [(1082, 784), (1082, 785)] INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')] INSERT INTO Faculty VALUES [(1082, 'Giuliano', 'Mark', 'Instructor', 'M', 2424, '224', 'NEB'), (1121, 'Goodrich', 'Michael', 'Professor', 'M', 3593, '219', 'NEB')]
tracking_orders
SELECT order_id FROM orders ORDER BY date_order_placed DESC LIMIT 1
What is the id of the most recent order?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_id FROM orders ORDER BY date_order_placed DESC LIMIT 1
Find the id of the order made most recently.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_id , customer_id FROM orders ORDER BY date_order_placed LIMIT 1
what are the order id and customer id of the oldest order?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_id , customer_id FROM orders ORDER BY date_order_placed LIMIT 1
Find the order id and customer id associated with the oldest order.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_id FROM shipments WHERE shipment_tracking_number = "3452"
Find the id of the order whose shipment tracking number is "3452".
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_id FROM shipments WHERE shipment_tracking_number = "3452"
Which order's shipment tracking number is "3452"? Give me the id of the order.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_item_id FROM order_items WHERE product_id = 11
Find the ids of all the order items whose product id is 11.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_item_id FROM order_items WHERE product_id = 11
Find all the order items whose product id is 11. What are the order item ids?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Packing"
List the name of all the distinct customers who have orders with status "Packing".
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Packing"
Which customers have orders with status "Packing"? Give me the customer names.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT T1.customer_details FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road"
Find the details of all the distinct customers who have orders with status "On Road".
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT T1.customer_details FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road"
What are the distinct customers who have orders with status "On Road"? Give me the customer details?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
What is the name of the customer who has the most orders?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
Which customer made the most orders? Find the customer name.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
What is the customer id of the customer who has the most orders?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
Find the id of the customer who made the most orders.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T2.order_id , T2.order_status FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T1.customer_name = "Jeramie"
Give me a list of id and status of orders which belong to the customer named "Jeramie".
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T2.order_id , T2.order_status FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T1.customer_name = "Jeramie"
Which orders are made by the customer named "Jeramie"? Give me the order ids and status.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T2.date_order_placed FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T1.customer_name = "Jeramie"
Find the dates of orders which belong to the customer named "Jeramie".
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T2.date_order_placed FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T1.customer_name = "Jeramie"
What are the dates of the orders made by the customer named "Jeramie"?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.date_order_placed >= "2009-01-01" AND T2.date_order_placed <= "2010-01-01"
Give me the names of customers who have placed orders between 2009-01-01 and 2010-01-01.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.date_order_placed >= "2009-01-01" AND T2.date_order_placed <= "2010-01-01"
Which customers made orders between 2009-01-01 and 2010-01-01? Find their names.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT T2.product_id FROM orders AS T1 JOIN order_items AS T2 ON T1.order_id = T2.order_id WHERE T1.date_order_placed >= "1975-01-01" AND T1.date_order_placed <= "1976-01-01"
Give me a list of distinct product ids from orders placed between 1975-01-01 and 1976-01-01?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT T2.product_id FROM orders AS T1 JOIN order_items AS T2 ON T1.order_id = T2.order_id WHERE T1.date_order_placed >= "1975-01-01" AND T1.date_order_placed <= "1976-01-01"
What are the distinct ids of products ordered between 1975-01-01 and 1976-01-01??
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road" INTERSECT SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Shipped"
Find the names of the customers who have order status both "On Road" and "Shipped".
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road" INTERSECT SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Shipped"
Which customers have both "On Road" and "Shipped" as order status? List the customer names.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road" INTERSECT SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Shipped"
Find the id of the customers who have order status both "On Road" and "Shipped".
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road" INTERSECT SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Shipped"
Which customers have both "On Road" and "Shipped" as order status? List the customer ids.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.date_order_placed FROM orders AS T1 JOIN shipments AS T2 ON T1.order_id = T2.order_id WHERE T2.shipment_tracking_number = 3452
When was the order placed whose shipment tracking number is 3452? Give me the date.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.date_order_placed FROM orders AS T1 JOIN shipments AS T2 ON T1.order_id = T2.order_id WHERE T2.shipment_tracking_number = 3452
On which day was the order placed whose shipment tracking number is 3452?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.date_order_placed FROM orders AS T1 JOIN shipments AS T2 ON T1.order_id = T2.order_id WHERE T2.invoice_number = 10
What is the placement date of the order whose invoice number is 10?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.date_order_placed FROM orders AS T1 JOIN shipments AS T2 ON T1.order_id = T2.order_id WHERE T2.invoice_number = 10
On what day was the order with invoice number 10 placed?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT count(*) , T3.product_id FROM orders AS T1 JOIN order_items AS T2 JOIN products AS T3 ON T1.order_id = T2.order_id AND T2.product_id = T3.product_id GROUP BY T3.product_id
List the count and id of each product in all the orders.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT count(*) , T3.product_id FROM orders AS T1 JOIN order_items AS T2 JOIN products AS T3 ON T1.order_id = T2.order_id AND T2.product_id = T3.product_id GROUP BY T3.product_id
For each product, return its id and the number of times it was ordered.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T3.product_name , count(*) FROM orders AS T1 JOIN order_items AS T2 JOIN products AS T3 ON T1.order_id = T2.order_id AND T2.product_id = T3.product_id GROUP BY T3.product_id
List the name and count of each product in all orders.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T3.product_name , count(*) FROM orders AS T1 JOIN order_items AS T2 JOIN products AS T3 ON T1.order_id = T2.order_id AND T2.product_id = T3.product_id GROUP BY T3.product_id
For each product, show its name and the number of times it was ordered.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_id FROM shipments WHERE shipment_date > "2000-01-01"
Find the ids of orders which are shipped after 2000-01-01.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_id FROM shipments WHERE shipment_date > "2000-01-01"
Which orders have shipment after 2000-01-01? Give me the order ids.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_id FROM shipments WHERE shipment_date = (SELECT max(shipment_date) FROM shipments)
Find the id of the order which is shipped most recently.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT order_id FROM shipments WHERE shipment_date = (SELECT max(shipment_date) FROM shipments)
Which order has the most recent shipment? Give me the order id.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT product_name FROM products ORDER BY product_name
List the names of all distinct products in alphabetical order.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT product_name FROM products ORDER BY product_name
Sort all the distinct products in alphabetical order.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT order_id FROM orders ORDER BY date_order_placed
List the ids of all distinct orders ordered by placed date.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT order_id FROM orders ORDER BY date_order_placed
What are ids of the all distinct orders, sorted by placement date?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.order_id FROM orders AS T1 JOIN order_items AS T2 ON T1.order_id = T2.order_id GROUP BY T1.order_id ORDER BY count(*) DESC LIMIT 1
What is the id of the order which has the most items?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.order_id FROM orders AS T1 JOIN order_items AS T2 ON T1.order_id = T2.order_id GROUP BY T1.order_id ORDER BY count(*) DESC LIMIT 1
Which order deals with the most items? Return the order id.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
What is the name of the customer who has the largest number of orders?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
Find the name of the customer who made the most orders.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT invoice_number FROM invoices WHERE invoice_date < "1989-09-03" OR invoice_date > "2007-12-25"
Find the invoice numbers which are created before 1989-09-03 or after 2007-12-25.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT invoice_number FROM invoices WHERE invoice_date < "1989-09-03" OR invoice_date > "2007-12-25"
What are the invoice numbers created before 1989-09-03 or after 2007-12-25?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT invoice_details FROM invoices WHERE invoice_date < "1989-09-03" OR invoice_date > "2007-12-25"
Find the distinct details of invoices which are created before 1989-09-03 or after 2007-12-25.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT DISTINCT invoice_details FROM invoices WHERE invoice_date < "1989-09-03" OR invoice_date > "2007-12-25"
What are the distinct details of invoices created before 1989-09-03 or after 2007-12-25?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T2.customer_name , count(*) FROM orders AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T2.customer_id HAVING count(*) >= 2
For each customer who has at least two orders, find the customer name and number of orders made.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T2.customer_name , count(*) FROM orders AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T2.customer_id HAVING count(*) >= 2
Which customers have made at least two orders? Give me each customer name and number of orders made.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T2.customer_name FROM orders AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T2.customer_id HAVING count(*) <= 2
Find the name of the customers who have at most two orders.
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T2.customer_name FROM orders AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T2.customer_id HAVING count(*) <= 2
What are the names of the customers who have made two or less orders?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 JOIN order_items AS T3 JOIN products AS T4 ON T1.customer_id = T2.customer_id AND T2.order_id = T3.order_id AND T3.product_id = T4.product_id WHERE T4.product_name = "food" GROUP BY T1.customer_id HAVING count(*) >= 1
List the names of the customers who have once bought product "food".
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 JOIN order_items AS T3 JOIN products AS T4 ON T1.customer_id = T2.customer_id AND T2.order_id = T3.order_id AND T3.product_id = T4.product_id WHERE T4.product_name = "food" GROUP BY T1.customer_id HAVING count(*) >= 1
What are the names of the customers who bought product "food" at least once?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 JOIN order_items AS T3 JOIN products AS T4 ON T1.customer_id = T2.customer_id AND T2.order_id = T3.order_id AND T3.product_id = T4.product_id WHERE T3.order_item_status = "Cancel" AND T4.product_name = "food" GROUP BY T1.customer_id HAVING count(*) >= 1
List the names of customers who have once canceled the purchase of the product "food" (the item status is "Cancel").
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
tracking_orders
SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 JOIN order_items AS T3 JOIN products AS T4 ON T1.customer_id = T2.customer_id AND T2.order_id = T3.order_id AND T3.product_id = T4.product_id WHERE T3.order_item_status = "Cancel" AND T4.product_name = "food" GROUP BY T1.customer_id HAVING count(*) >= 1
Which customers have ever canceled the purchase of the product "food" (the item status is "Cancel")?
PRAGMA foreign_keys = ON; CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_name` VARCHAR(80), `customer_details` VARCHAR(255) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_date` DATETIME, `invoice_details` VARCHAR(255) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(80), `product_details` VARCHAR(255) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status` VARCHAR(10) NOT NULL, `order_item_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, `other_shipment_details` VARCHAR(255), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ) ); CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ) ); INSERT INTO Customers (`customer_id`, `customer_name`, `customer_details`) VALUES (1, 'Savannah', 'rerum')INSERT INTO Invoices (`invoice_number`, `invoice_date`, `invoice_details`) VALUES (1, '1989-09-03 16:03:05', 'vitae')INSERT INTO Orders (`order_id`, `customer_id`, `order_status`, `date_order_placed`, `order_details`) VALUES (1, 2, 'Shipped', '2009-02-21 15:26:19', NULL)INSERT INTO Products (`product_id`, `product_name`, `product_details`) VALUES (1, 'food', NULL)INSERT INTO Shipments (`shipment_id`, `order_id`, `invoice_number`, `shipment_tracking_number`, `shipment_date`, `other_shipment_details`) VALUES (1, 5, 13, '3452', '1983-08-13 22:34:11', NULL)INSERT INTO Order_Items (`order_item_id`, `product_id`, `order_id`, `order_item_status`, `order_item_details`) VALUES (1, 4, 6, 'Finish', NULL)INSERT INTO Shipment_Items (`shipment_id`, `order_item_id`) VALUES (11, 12)
architecture
SELECT count(*) FROM architect WHERE gender = 'female'
How many architects are female?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT name , nationality , id FROM architect WHERE gender = 'male' ORDER BY name
List the name, nationality and id of all male architects ordered by their names lexicographically.
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT max(T1.length_meters) , T2.name FROM bridge AS T1 JOIN architect AS T2 ON T1.architect_id = T2.id
What is the maximum length in meters for the bridges and what are the architects' names?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT avg(length_feet) FROM bridge
What is the average length in feet of the bridges?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT name , built_year FROM mill WHERE TYPE = 'Grondzeiler'
What are the names and year of construction for the mills of 'Grondzeiler' type?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT DISTINCT T1.name , T1.nationality FROM architect AS T1 JOIN mill AS t2 ON T1.id = T2.architect_id
What are the distinct names and nationalities of the architects who have ever built a mill?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT name FROM mill WHERE LOCATION != 'Donceel'
What are the names of the mills which are not located in 'Donceel'?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT DISTINCT T1.type FROM mill AS T1 JOIN architect AS t2 ON T1.architect_id = T2.id WHERE T2.nationality = 'American' OR T2.nationality = 'Canadian'
What are the distinct types of mills that are built by American or Canadian architects?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT T1.id , T1.name FROM architect AS T1 JOIN bridge AS T2 ON T1.id = T2.architect_id GROUP BY T1.id HAVING count(*) >= 3
What are the ids and names of the architects who built at least 3 bridges ?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT T1.id , T1.name , T1.nationality FROM architect AS T1 JOIN mill AS T2 ON T1.id = T2.architect_id GROUP BY T1.id ORDER BY count(*) DESC LIMIT 1
What is the id, name and nationality of the architect who built most mills?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT T1.id , T1.name , T1.gender FROM architect AS T1 JOIN bridge AS T2 ON T1.id = T2.architect_id GROUP BY T1.id HAVING count(*) = 2 UNION SELECT T1.id , T1.name , T1.gender FROM architect AS T1 JOIN mill AS T2 ON T1.id = T2.architect_id GROUP BY T1.id HAVING count(*) = 1
What are the ids, names and genders of the architects who built two bridges or one mill?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT LOCATION FROM bridge WHERE name = 'Kolob Arch' OR name = 'Rainbow Bridge'
What is the location of the bridge named 'Kolob Arch' or 'Rainbow Bridge'?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT name FROM mill WHERE name LIKE '%Moulin%'
Which of the mill names contains the french word 'Moulin'?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT DISTINCT T1.name FROM mill AS T1 JOIN architect AS t2 ON T1.architect_id = T2.id JOIN bridge AS T3 ON T3.architect_id = T2.id WHERE T3.length_meters > 80
What are the distinct name of the mills built by the architects who have also built a bridge longer than 80 meters?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT TYPE , count(*) FROM mill GROUP BY TYPE ORDER BY count(*) DESC LIMIT 1
What is the most common mill type, and how many are there?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT count(*) FROM architect WHERE id NOT IN ( SELECT architect_id FROM mill WHERE built_year < 1850 );
How many architects haven't built a mill before year 1850?
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
architecture
SELECT t1.name FROM bridge AS t1 JOIN architect AS t2 ON t1.architect_id = t2.id WHERE t2.nationality = 'American' ORDER BY t1.length_feet
show the name of all bridges that was designed by american archtect, and sort the result by the bridge feet length.
PRAGMA foreign_keys = ON; CREATE TABLE "architect" ( "id" text, "name" text, "nationality" text, "gender" text, primary key("id") ); CREATE TABLE "bridge" ( "architect_id" int, "id" int, "name" text, "location" text, "length_meters" real, "length_feet" real, primary key("id"), foreign key ("architect_id" ) references `architect`("id") ); CREATE TABLE "mill" ( "architect_id" int, "id" int, "location" text, "name" text, "type" text, "built_year" int, "notes" text, primary key ("id"), foreign key ("architect_id" ) references `architect`("id") ); INSERT INTO "architect" VALUES (1, "Frank Lloyd Wright", "American", "male"); INSERT INTO "bridge" VALUES (1,"1","Xian Ren Qiao (Fairy Bridge)","Guangxi , China","121","400")INSERT INTO "mill" VALUES (1,1,"Coswarem","Le Vieux Molen","Grondzeiler","1840","Molenechos (Dutch)")
culture_company
SELECT count(*) FROM book_club
How many book clubs are there?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT count(*) FROM book_club
Count the number of book clubs.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT book_title , author_or_editor FROM book_club WHERE YEAR > 1989
show the titles, and authors or editors for all books made after the year 1989.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT book_title , author_or_editor FROM book_club WHERE YEAR > 1989
What are the titles and authors or editors that correspond to books made after 1989?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT DISTINCT publisher FROM book_club
Show all distinct publishers for books.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT DISTINCT publisher FROM book_club
What are all the different book publishers?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT YEAR , book_title , publisher FROM book_club ORDER BY YEAR DESC
Show the years, book titles, and publishers for all books, in descending order by year.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT YEAR , book_title , publisher FROM book_club ORDER BY YEAR DESC
What are the years, titles, and publishers for all books, ordered by year descending?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT publisher , count(*) FROM book_club GROUP BY publisher
Show all publishers and the number of books for each publisher.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT publisher , count(*) FROM book_club GROUP BY publisher
How many books are there for each publisher?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT publisher FROM book_club GROUP BY publisher ORDER BY count(*) DESC LIMIT 1
What is the publisher with most number of books?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT publisher FROM book_club GROUP BY publisher ORDER BY count(*) DESC LIMIT 1
Return the publisher that has published the most books.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT category , count(*) FROM book_club GROUP BY category
Show all book categories and the number of books in each category.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT category , count(*) FROM book_club GROUP BY category
How many books fall into each category?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT category FROM book_club WHERE YEAR > 1989 GROUP BY category HAVING count(*) >= 2
List categories that have at least two books after year 1989.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT category FROM book_club WHERE YEAR > 1989 GROUP BY category HAVING count(*) >= 2
What categories have two or more corresponding books that were made after 1989?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT publisher FROM book_club WHERE YEAR = 1989 INTERSECT SELECT publisher FROM book_club WHERE YEAR = 1990
Show publishers with a book published in 1989 and a book in 1990.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT publisher FROM book_club WHERE YEAR = 1989 INTERSECT SELECT publisher FROM book_club WHERE YEAR = 1990
What are the publishers who have published a book in both 1989 and 1990?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT publisher FROM book_club EXCEPT SELECT publisher FROM book_club WHERE YEAR = 1989
Show all publishers which do not have a book in 1989.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT publisher FROM book_club EXCEPT SELECT publisher FROM book_club WHERE YEAR = 1989
Which publishers did not publish a book in 1989?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT title , YEAR , director FROM movie ORDER BY budget_million
Show all movie titles, years, and directors, ordered by budget.
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);
culture_company
SELECT title , YEAR , director FROM movie ORDER BY budget_million
What are the titles, years, and directors of all movies, ordered by budget in millions?
PRAGMA foreign_keys = ON; CREATE TABLE "book_club" ( "book_club_id" int, "Year" int, "Author_or_Editor" text, "Book_Title" text, "Publisher" text, "Category" text, "Result" text, PRIMARY KEY ("book_club_id") ); CREATE TABLE "movie" ( "movie_id" int, "Title" text, "Year" int, "Director" text, "Budget_million" real, "Gross_worldwide" int, PRIMARY KEY("movie_id") ); CREATE TABLE "culture_company" ( "Company_name" text, "Type" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, "book_club_id" text, "movie_id" text, PRIMARY KEY("Company_name"), FOREIGN KEY ("book_club_id") REFERENCES "book_club"("book_club_id"), FOREIGN KEY ("movie_id") REFERENCES "movie"("movie_id") ); INSERT INTO "book_club" VALUES (1, "1989","Michael Nava","Goldenboy","Alyson","Gay M/SF","Won [A ]"); INSERT INTO "movie" VALUES (1, "The Boondock Saints","1999","Troy Duffy","6","30471"); INSERT INTO "culture_company" VALUES ("Culture China","Corporate","China","18.77",1,2);