db_id
stringclasses
127 values
query
stringlengths
20
523
question
stringlengths
16
224
schema
stringclasses
127 values
customers_and_invoices
SELECT count(*) FROM Financial_transactions AS T1 JOIN Accounts AS T2 ON T1.account_id = T2.account_id WHERE T2.account_name = "337"
How many transaction does account with name 337 have?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT count(*) FROM Financial_transactions AS T1 JOIN Accounts AS T2 ON T1.account_id = T2.account_id WHERE T2.account_name = "337"
Count the number of financial transactions that the account with the name 337 has.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT avg(transaction_amount) , min(transaction_amount) , max(transaction_amount) , sum(transaction_amount) FROM Financial_transactions
What is the average, minimum, maximum, and total transaction amount?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT avg(transaction_amount) , min(transaction_amount) , max(transaction_amount) , sum(transaction_amount) FROM Financial_transactions
Return the average, minimum, maximum, and total transaction amounts.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT transaction_id FROM Financial_transactions WHERE transaction_amount > (SELECT avg(transaction_amount) FROM Financial_transactions)
Show ids for all transactions whose amounts are greater than the average.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT transaction_id FROM Financial_transactions WHERE transaction_amount > (SELECT avg(transaction_amount) FROM Financial_transactions)
What are the ids for transactions that have an amount greater than the average amount of a transaction?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT transaction_type , sum(transaction_amount) FROM Financial_transactions GROUP BY transaction_type
Show the transaction types and the total amount of transactions.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT transaction_type , sum(transaction_amount) FROM Financial_transactions GROUP BY transaction_type
What are total transaction amounts for each transaction type?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.account_name , T1.account_id , count(*) FROM Financial_transactions AS T1 JOIN Accounts AS T2 ON T1.account_id = T2.account_id GROUP BY T1.account_id
Show the account name, id and the number of transactions for each account.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.account_name , T1.account_id , count(*) FROM Financial_transactions AS T1 JOIN Accounts AS T2 ON T1.account_id = T2.account_id GROUP BY T1.account_id
Return the names and ids of each account, as well as the number of transactions.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT account_id FROM Financial_transactions GROUP BY account_id ORDER BY count(*) DESC LIMIT 1
Show the account id with most number of transactions.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT account_id FROM Financial_transactions GROUP BY account_id ORDER BY count(*) DESC LIMIT 1
What is the id of the account with the most transactions?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T1.account_id , T2.account_name FROM Financial_transactions AS T1 JOIN Accounts AS T2 ON T1.account_id = T2.account_id GROUP BY T1.account_id HAVING count(*) >= 4
Show the account id and name with at least 4 transactions.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T1.account_id , T2.account_name FROM Financial_transactions AS T1 JOIN Accounts AS T2 ON T1.account_id = T2.account_id GROUP BY T1.account_id HAVING count(*) >= 4
What are the ids and names of accounts with 4 or more transactions?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT DISTINCT product_size FROM Products
Show all product sizes.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT DISTINCT product_size FROM Products
What are the different product sizes?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT DISTINCT product_color FROM Products
Show all product colors.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT DISTINCT product_color FROM Products
What are the different product colors?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT invoice_number , count(*) FROM Financial_transactions GROUP BY invoice_number
Show the invoice number and the number of transactions for each invoice.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT invoice_number , count(*) FROM Financial_transactions GROUP BY invoice_number
How many transactions correspond to each invoice number?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.invoice_number , T2.invoice_date FROM Financial_transactions AS T1 JOIN Invoices AS T2 ON T1.invoice_number = T2.invoice_number GROUP BY T1.invoice_number ORDER BY count(*) DESC LIMIT 1
What is the invoice number and invoice date for the invoice with most number of transactions?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.invoice_number , T2.invoice_date FROM Financial_transactions AS T1 JOIN Invoices AS T2 ON T1.invoice_number = T2.invoice_number GROUP BY T1.invoice_number ORDER BY count(*) DESC LIMIT 1
What is the invoice number and invoice date corresponding to the invoice with the greatest number of transactions?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT count(*) FROM Invoices
How many invoices do we have?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT count(*) FROM Invoices
Count the number of invoices.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T1.invoice_date , T1.order_id , T2.order_details FROM Invoices AS T1 JOIN Orders AS T2 ON T1.order_id = T2.order_id
Show invoice dates and order id and details for all invoices.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T1.invoice_date , T1.order_id , T2.order_details FROM Invoices AS T1 JOIN Orders AS T2 ON T1.order_id = T2.order_id
What are the invoice dates, order ids, and order details for all invoices?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT order_id , count(*) FROM Invoices GROUP BY order_id
Show the order ids and the number of invoices for each order.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT order_id , count(*) FROM Invoices GROUP BY order_id
How many invoices correspond to each order id?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.order_id , T2.order_details FROM Invoices AS T1 JOIN Orders AS T2 ON T1.order_id = T2.order_id GROUP BY T2.order_id HAVING count(*) > 2
What is the order id and order details for the order more than two invoices.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.order_id , T2.order_details FROM Invoices AS T1 JOIN Orders AS T2 ON T1.order_id = T2.order_id GROUP BY T2.order_id HAVING count(*) > 2
Return the order ids and details for orderes with two or more invoices.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.customer_last_name , T1.customer_id , T2.phone_number FROM Orders AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
What is the customer last name, id and phone number with most number of orders?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.customer_last_name , T1.customer_id , T2.phone_number FROM Orders AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
Return the last name, id and phone number of the customer who has made the greatest number of orders.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT product_name FROM Products EXCEPT SELECT T1.product_name FROM Products AS T1 JOIN Order_items AS T2 ON T1.product_id = T2.product_id
Show all product names without an order.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT product_name FROM Products EXCEPT SELECT T1.product_name FROM Products AS T1 JOIN Order_items AS T2 ON T1.product_id = T2.product_id
What are the names of products that have never been ordered?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.product_name , sum(T1.product_quantity) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id = T2.product_id GROUP BY T2.product_name
Show all product names and the total quantity ordered for each product name.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.product_name , sum(T1.product_quantity) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id = T2.product_id GROUP BY T2.product_name
What are the different product names, and what is the sum of quantity ordered for each product?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT order_id , count(*) FROM Order_items GROUP BY order_id
Show the order ids and the number of items in each order.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT order_id , count(*) FROM Order_items GROUP BY order_id
How many order items correspond to each order id?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT product_id , count(DISTINCT order_id) FROM Order_items GROUP BY product_id
Show the product ids and the number of unique orders containing each product.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT product_id , count(DISTINCT order_id) FROM Order_items GROUP BY product_id
How many distinct order ids correspond to each product?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.product_name , count(*) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id = T2.product_id JOIN Orders AS T3 ON T3.order_id = T1.order_id GROUP BY T2.product_name
Show all product names and the number of customers having an order on each product.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT T2.product_name , count(*) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id = T2.product_id JOIN Orders AS T3 ON T3.order_id = T1.order_id GROUP BY T2.product_name
What are teh names of the different products, as well as the number of customers who have ordered each product.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT order_id , count(DISTINCT product_id) FROM Order_items GROUP BY order_id
Show order ids and the number of products in each order.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT order_id , count(DISTINCT product_id) FROM Order_items GROUP BY order_id
How many different products correspond to each order id?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT order_id , sum(product_quantity) FROM Order_items GROUP BY order_id
Show order ids and the total quantity in each order.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT order_id , sum(product_quantity) FROM Order_items GROUP BY order_id
Give the order ids for all orders, as well as the total product quantity in each.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT count(*) FROM products WHERE product_id NOT IN ( SELECT product_id FROM Order_items )
How many products were not included in any order?
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
customers_and_invoices
SELECT count(*) FROM products WHERE product_id NOT IN ( SELECT product_id FROM Order_items )
Count the number of products that were never ordered.
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `gender` VARCHAR(1), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `town_city` VARCHAR(50), `state_county_province` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_order_placed` DATETIME NOT NULL, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_date` DATETIME, FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `date_account_opened` DATETIME, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Product_Categories` ( `production_type_code` VARCHAR(15) PRIMARY KEY, `product_type_description` VARCHAR(80), `vat_rating` DECIMAL(19,4) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `production_type_code` VARCHAR(15) NOT NULL, `unit_price` DECIMAL(19,4), `product_name` VARCHAR(80), `product_color` VARCHAR(20), `product_size` VARCHAR(20), FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` ) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `account_id` INTEGER NOT NULL, `invoice_number` INTEGER, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DECIMAL(19,4), `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_quantity` VARCHAR(50), `other_order_item_details` VARCHAR(255), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ); CREATE TABLE `Invoice_Line_Items` ( `order_item_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `product_title` VARCHAR(80), `product_quantity` VARCHAR(50), `product_price` DECIMAL(19,4), `derived_product_cost` DECIMAL(19,4), `derived_vat_payable` DECIMAL(19,4), `derived_total_cost` DECIMAL(19,4), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ), FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ) ); INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA'); INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL); INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48'); INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular'); INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400'); INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium'); INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600'); INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL); INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200');
wedding
SELECT count(*) FROM Church WHERE Open_Date < 1850
How many churches opened before 1850 are there?
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT name , open_date , organized_by FROM Church
Show the name, open date, and organizer for all churches.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT name FROM church ORDER BY open_date DESC
List all church names in descending order of opening date.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT open_date FROM church GROUP BY open_date HAVING count(*) >= 2
Show the opening year in whcih at least two churches opened.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT organized_by , name FROM church WHERE open_date BETWEEN 1830 AND 1840
Show the organizer and name for churches that opened between 1830 and 1840.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT open_date , count(*) FROM church GROUP BY open_date
Show all opening years and the number of churches that opened in that year.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT name , open_date FROM church ORDER BY open_date DESC LIMIT 3
Show the name and opening year for three churches that opened most recently.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT count(*) FROM people WHERE is_male = 'F' AND age > 30
How many female people are older than 30 in our record?
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT country FROM people WHERE age < 25 INTERSECT SELECT country FROM people WHERE age > 30
Show the country where people older than 30 and younger than 25 are from.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT min(age) , max(age) , avg(age) FROM people
Show the minimum, maximum, and average age for all people.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT name , country FROM people WHERE age < (SELECT avg(age) FROM people)
Show the name and country for all people whose age is smaller than the average.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT T2.name , T3.name FROM wedding AS T1 JOIN people AS T2 ON T1.male_id = T2.people_id JOIN people AS T3 ON T1.female_id = T3.people_id WHERE T1.year > 2014
Show the pair of male and female names in all weddings after year 2014
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT name , age FROM people WHERE is_male = 'T' AND people_id NOT IN (SELECT male_id FROM wedding)
Show the name and age for all male people who don't have a wedding.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT name FROM church EXCEPT SELECT T1.name FROM church AS T1 JOIN wedding AS T2 ON T1.church_id = T2.church_id WHERE T2.year = 2015
Show all church names except for those that had a wedding in year 2015.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT T1.name FROM church AS T1 JOIN wedding AS T2 ON T1.church_id = T2.church_id GROUP BY T1.church_id HAVING count(*) >= 2
Show all church names that have hosted least two weddings.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT T2.name FROM wedding AS T1 JOIN people AS T2 ON T1.female_id = T2.people_id WHERE T1.year = 2016 AND T2.is_male = 'F' AND T2.country = 'Canada'
Show the names for all females from Canada having a wedding in year 2016.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT count(*) FROM wedding WHERE YEAR = 2016
How many weddings are there in year 2016?
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT T4.name FROM wedding AS T1 JOIN people AS T2 ON T1.male_id = T2.people_id JOIN people AS T3 ON T1.female_id = T3.people_id JOIN church AS T4 ON T4.church_id = T1.church_id WHERE T2.age > 30 OR T3.age > 30
Show the church names for the weddings of all people older than 30.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT country , count(*) FROM people GROUP BY country
Show all countries and the number of people from each country.
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
wedding
SELECT COUNT (DISTINCT church_id) FROM wedding WHERE YEAR = 2016
How many churches have a wedding in year 2016?
CREATE TABLE "people" ( "People_ID" int, "Name" text, "Country" text, "Is_Male" text, "Age" int, PRIMARY KEY ("People_ID") ); CREATE TABLE "church" ( "Church_ID" int, "Name" text, "Organized_by" text, "Open_Date" int, "Continuation_of" text, PRIMARY KEY ("Church_ID") ); CREATE TABLE "wedding" ( "Church_ID" int, "Male_ID" int, "Female_ID" int, "Year" int, PRIMARY KEY ("Church_ID","Male_ID","Female_ID"), FOREIGN KEY ("Church_ID") REFERENCES `church`("Church_ID"), FOREIGN KEY ("Male_ID") REFERENCES `people`("People_ID"), FOREIGN KEY ("Female_ID") REFERENCES `people`("People_ID") ); INSERT INTO "people" VALUES ("1","Mike Weir","Canada","T",34); INSERT INTO "church" VALUES (1,"Pure Church of Christ","Wycam Clark","1831","Church of Christ"); INSERT INTO "wedding" VALUES (1,1,2,"2014");
theme_gallery
SELECT count(*) FROM artist
How many artists do we have?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT count(*) FROM artist
Count the number of artists.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT name , age , country FROM artist ORDER BY Year_Join
Show all artist name, age, and country ordered by the yeared they joined.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT name , age , country FROM artist ORDER BY Year_Join
What are the names, ages, and countries of artists, sorted by the year they joined?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT DISTINCT country FROM artist
What are all distinct country for artists?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT DISTINCT country FROM artist
Return the different countries for artists.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT name , year_join FROM artist WHERE country != 'United States'
Show all artist names and the year joined who are not from United States.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT name , year_join FROM artist WHERE country != 'United States'
What are the names and year of joining for artists that do not have the country "United States"?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT count(*) FROM artist WHERE age > 46 AND year_join > 1990
How many artists are above age 46 and joined after 1990?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT count(*) FROM artist WHERE age > 46 AND year_join > 1990
Count the number of artists who are older than 46 and joined after 1990.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT avg(age) , min(age) FROM artist WHERE country = 'United States'
What is the average and minimum age of all artists from United States.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT avg(age) , min(age) FROM artist WHERE country = 'United States'
Return the average and minimum ages across artists from the United States.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT name FROM artist ORDER BY year_join DESC LIMIT 1
What is the name of the artist who joined latest?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT name FROM artist ORDER BY year_join DESC LIMIT 1
Return the name of the artist who has the latest join year.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT count(*) FROM exhibition WHERE YEAR >= 2005
How many exhibition are there in year 2005 or after?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT count(*) FROM exhibition WHERE YEAR >= 2005
Count the number of exhibitions that happened in or after 2005.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT theme , YEAR FROM exhibition WHERE ticket_price < 15
Show theme and year for all exhibitions with ticket prices lower than 15.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT theme , YEAR FROM exhibition WHERE ticket_price < 15
What are the theme and year for all exhibitions that have a ticket price under 15?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT T2.name , count(*) FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id GROUP BY T1.artist_id
Show all artist names and the number of exhibitions for each artist.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT T2.name , count(*) FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id GROUP BY T1.artist_id
How many exhibitions has each artist had?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT T2.name , T2.country FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id GROUP BY T1.artist_id ORDER BY count(*) DESC LIMIT 1
What is the name and country for the artist with most number of exhibitions?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT T2.name , T2.country FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id GROUP BY T1.artist_id ORDER BY count(*) DESC LIMIT 1
Return the name and country corresponding to the artist who has had the most exhibitions.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT name FROM artist WHERE artist_id NOT IN (SELECT artist_id FROM exhibition)
Show names for artists without any exhibition.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT name FROM artist WHERE artist_id NOT IN (SELECT artist_id FROM exhibition)
What are the names of artists that have not had any exhibitions?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT T1.theme , T2.name FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id WHERE T1.ticket_price > (SELECT avg(ticket_price) FROM exhibition)
What is the theme and artist name for the exhibition with a ticket price higher than the average?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT T1.theme , T2.name FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id WHERE T1.ticket_price > (SELECT avg(ticket_price) FROM exhibition)
Return the names of artists and the themes of their exhibitions that had a ticket price higher than average.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT avg(ticket_price) , min(ticket_price) , max(ticket_price) FROM exhibition WHERE YEAR < 2009
Show the average, minimum, and maximum ticket prices for exhibitions for all years before 2009.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT avg(ticket_price) , min(ticket_price) , max(ticket_price) FROM exhibition WHERE YEAR < 2009
What are the average, minimum, and maximum ticket prices for exhibitions that happened prior to 2009?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT theme , YEAR FROM exhibition ORDER BY ticket_price DESC
Show theme and year for all exhibitions in an descending order of ticket price.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT theme , YEAR FROM exhibition ORDER BY ticket_price DESC
What are the themes and years for exhibitions, sorted by ticket price descending?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT T2.theme , T1.date , T1.attendance FROM exhibition_record AS T1 JOIN exhibition AS T2 ON T1.exhibition_id = T2.exhibition_id WHERE T2.year = 2004
What is the theme, date, and attendance for the exhibition in year 2004?
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);
theme_gallery
SELECT T2.theme , T1.date , T1.attendance FROM exhibition_record AS T1 JOIN exhibition AS T2 ON T1.exhibition_id = T2.exhibition_id WHERE T2.year = 2004
Return the themes, dates, and attendance for exhibitions that happened in 2004.
CREATE TABLE "artist" ( "Artist_ID" int, "Name" text, "Country" text, "Year_Join" int, "Age" int, PRIMARY KEY ("Artist_ID") ); CREATE TABLE "exhibition" ( "Exhibition_ID" int, "Year" int, "Theme" text, "Artist_ID" int, "Ticket_Price" real, PRIMARY KEY ("Exhibition_ID"), FOREIGN KEY (`Artist_ID`) REFERENCES `artist`(`Artist_ID`) ); CREATE TABLE "exhibition_record" ( "Exhibition_ID" int, "Date" text, "Attendance" int, PRIMARY KEY ("Exhibition_ID","Date"), FOREIGN KEY (`Exhibition_ID`) REFERENCES `exhibition`(`Exhibition_ID`) ); INSERT INTO "artist" VALUES (1,"Vijay Singh","Fiji","1998",45); INSERT INTO "exhibition" VALUES (1,"2004","Santa Claus",1,"19.95"); INSERT INTO "exhibition_record" VALUES (1,"December 2",965);