db_id
stringclasses
40 values
question
stringlengths
22
185
SQL
stringlengths
22
608
db_schema_TC
stringclasses
280 values
db_schema_T
stringclasses
280 values
db_schema
stringclasses
40 values
e_commerce
How many items are shipped?
SELECT count(*) FROM Shipment_Items
CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
How many products have been shipped?
SELECT count(*) FROM Shipment_Items
CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What is the product average price?
SELECT avg(product_price) FROM Products
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
How much do the products cost on average?
SELECT avg(product_price) FROM Products
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What is the average price of the products being ordered?
SELECT avg(T1.product_price) FROM Products AS T1 JOIN Order_items AS T2 ON T1.product_id = T2.product_id
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What is the price of all products being ordered on average?
SELECT avg(T1.product_price) FROM Products AS T1 JOIN Order_items AS T2 ON T1.product_id = T2.product_id
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What are the email address, town and county of the customers who are of the least common gender?
SELECT email_address , town_city , county FROM Customers WHERE gender_code = ( SELECT gender_code FROM Customers GROUP BY gender_code ORDER BY count(*) ASC LIMIT 1 )
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) )
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What are the email addresses, cities, and counties listed for all cusomters who are from the gender that orders less often?
SELECT email_address , town_city , county FROM Customers WHERE gender_code = ( SELECT gender_code FROM Customers GROUP BY gender_code ORDER BY count(*) ASC LIMIT 1 )
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) )
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
List the order date of the orders who are placed by customers with at least 2 payment methods.
SELECT date_order_placed FROM Orders WHERE customer_id IN ( SELECT T1.customer_id FROM Customers AS T1 JOIN Customer_Payment_Methods AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id HAVING count(*) >= 2 )
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What is the date of all orders that have been placed by customers with at least 2 payment methods?
SELECT date_order_placed FROM Orders WHERE customer_id IN ( SELECT T1.customer_id FROM Customers AS T1 JOIN Customer_Payment_Methods AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id HAVING count(*) >= 2 )
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What is the most uncommon order status?
SELECT order_status_code FROM Orders GROUP BY order_status_code ORDER BY count(*) LIMIT 1
CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What is the least common order status?
SELECT order_status_code FROM Orders GROUP BY order_status_code ORDER BY count(*) LIMIT 1
CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
For all the products sold for more than 3 times, list their id and description.
SELECT T1.product_id , T1.product_description FROM Products AS T1 JOIN Order_items AS T2 ON T1.product_id = T2.product_id GROUP BY T1.product_id HAVING count(*) > 3
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
For all products sold more than 3 times, what are their ids and descriptions?
SELECT T1.product_id , T1.product_description FROM Products AS T1 JOIN Order_items AS T2 ON T1.product_id = T2.product_id GROUP BY T1.product_id HAVING count(*) > 3
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
List the invoice dates and ids of the invoices causing at least 2 shipments.
SELECT T1.invoice_date , T1.invoice_number FROM Invoices AS T1 JOIN Shipments AS T2 ON T1.invoice_number = T2.invoice_number GROUP BY T1.invoice_number HAVING count(*) >= 2
CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What are the dates and ids of the invoices that are related to at least 2 shipments?
SELECT T1.invoice_date , T1.invoice_number FROM Invoices AS T1 JOIN Shipments AS T2 ON T1.invoice_number = T2.invoice_number GROUP BY T1.invoice_number HAVING count(*) >= 2
CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
what are all shipment tracking numbers and shipment dates?
SELECT shipment_tracking_number , shipment_date FROM Shipments
CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What are the tracking numbers and dates for all shipments listed?
SELECT shipment_tracking_number , shipment_date FROM Shipments
CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What are the color, description and size of the products priced below the maximum price.
SELECT product_color , product_description , product_size FROM Products WHERE product_price < ( SELECT max(product_price) FROM products )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
e_commerce
What are the colors , descriptions , and sizes for all products that are not at the maximum price ?
select product_color , product_description , product_size from products where product_price != ( select max(product_price) from products )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) )
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY , `parent_product_id` INTEGER, `product_name` VARCHAR(80), `product_price` DECIMAL(19,4) DEFAULT 0, `product_color` VARCHAR(50), `product_size` VARCHAR(50), `product_description` VARCHAR(255) ) CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `gender_code` VARCHAR(1) NOT NULL, `customer_first_name` VARCHAR(50), `customer_middle_initial` VARCHAR(1), `customer_last_name` VARCHAR(50), `email_address` VARCHAR(255), `login_name` VARCHAR(80), `login_password` VARCHAR(20), `phone_number` VARCHAR(255), `address_line_1` VARCHAR(255), `town_city` VARCHAR(50), `county` VARCHAR(50), `country` VARCHAR(50) ) CREATE TABLE `Customer_Payment_Methods` ( `customer_id` INTEGER NOT NULL, `payment_method_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Invoices` ( `invoice_number` INTEGER PRIMARY KEY, `invoice_status_code` VARCHAR(10) NOT NULL, `invoice_date` DATETIME ) CREATE TABLE `Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(10) NOT NULL, `date_order_placed` DATETIME NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) CREATE TABLE `Order_Items` ( `order_item_id` INTEGER PRIMARY KEY , `product_id` INTEGER NOT NULL, `order_id` INTEGER NOT NULL, `order_item_status_code` VARCHAR(10) NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipments` ( `shipment_id` INTEGER PRIMARY KEY, `order_id` INTEGER NOT NULL, `invoice_number` INTEGER NOT NULL, `shipment_tracking_number` VARCHAR(80), `shipment_date` DATETIME, FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ), FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` ) ) CREATE TABLE `Shipment_Items` ( `shipment_id` INTEGER NOT NULL, `order_item_id` INTEGER NOT NULL, PRIMARY KEY (`shipment_id`,`order_item_id`), FOREIGN KEY (`shipment_id` ) REFERENCES `Shipments`(`shipment_id` ), FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ) )
bbc_channels
Return the names of directors who are older than the average age.
SELECT name FROM director WHERE age > (SELECT avg(age) FROM director)
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") )
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
Find the the name of the oldest director.
SELECT name FROM director ORDER BY age DESC LIMIT 1
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") )
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
How many channels have the word 'bbc' in their internet link?
SELECT count(*) FROM channel WHERE internet LIKE "%bbc%"
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
How many different digital terrestrial channels are there?
SELECT count(DISTINCT Digital_terrestrial_channel) FROM channel
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
List all program titles in the order of starting year. List the most recent one first.
SELECT title FROM program ORDER BY start_year DESC
CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
Which director is in charge of the most programs?
SELECT t2.name FROM program AS t1 JOIN director AS t2 ON t1.director_id = t2.director_id GROUP BY t1.director_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
Find the name and age of the director who is in charge of the most programs?
SELECT t2.name , t2.age FROM program AS t1 JOIN director AS t2 ON t1.director_id = t2.director_id GROUP BY t1.director_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
Return the title of the program that began most recently.
SELECT title FROM program ORDER BY start_year DESC LIMIT 1
CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
Find the name and website link of the channels that have more than one program.
SELECT t1.name , t1.internet FROM channel AS t1 JOIN program AS t2 ON t1.channel_id = t2.channel_id GROUP BY t1.channel_id HAVING count(*) > 1
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
Find the number of programs for each channel. Return the name of each channel as well.
SELECT t1.name , count(*) FROM channel AS t1 JOIN program AS t2 ON t1.channel_id = t2.channel_id GROUP BY t1.channel_id
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
Find the number of channels that do not run any program.
SELECT count(*) FROM channel WHERE channel_id NOT IN (SELECT channel_id FROM program)
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
What is the name of the director who is in the "Dracula" program?
SELECT t2.name FROM program AS t1 JOIN director AS t2 ON t1.director_id = t2.director_id WHERE t1.title = 'Dracula'
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
Find the name and internet web of the channel that is directed by the most directors.
SELECT t1.name , t1.internet FROM channel AS t1 JOIN director_admin AS t2 ON t1.channel_id = t2.channel_id GROUP BY t1.channel_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
Find the name of the directors whose age is between 30 and 60.
SELECT name FROM director WHERE age BETWEEN 30 AND 60
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") )
CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
give me the name of channels that have both a director younger than 40 and a director older than 60.
SELECT t1.name FROM channel AS t1 JOIN director_admin AS t2 ON t1.channel_id = t2.channel_id JOIN director AS t3 ON t2.director_id = t3.director_id WHERE t3.age < 40 INTERSECT SELECT t1.name FROM channel AS t1 JOIN director_admin AS t2 ON t1.channel_id = t2.channel_id JOIN director AS t3 ON t2.director_id = t3.director_id WHERE t3.age > 60
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
bbc_channels
Find the id and name of the channel that is not directed by Hank Baskett.
SELECT t1.name , t1.channel_id FROM channel AS t1 JOIN director_admin AS t2 ON t1.channel_id = t2.channel_id JOIN director AS t3 ON t2.director_id = t3.director_id WHERE t3.name != "Hank Baskett"
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
CREATE TABLE "channel" ( "Channel_ID" int, "Name" text, "Analogue_terrestrial_channel" text, "Digital_terrestrial_channel" text, "Internet" text, PRIMARY KEY ("Channel_ID") ) CREATE TABLE "director" ( "Director_ID" int, "Name" text, "Age" int, PRIMARY KEY ("Director_ID") ) CREATE TABLE "program" ( "Program_ID" int, "Start_Year" real, "Title" text, "Director_ID" int, "Channel_ID" int, PRIMARY KEY ("Program_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") ) CREATE TABLE "director_admin" ( "Director_ID" int, "Channel_ID" int, "Is_first_director" bool, PRIMARY KEY ("Director_ID","Channel_ID"), FOREIGN KEY ("Director_ID") REFERENCES "director"("Director_ID"), FOREIGN KEY ("Channel_ID") REFERENCES "channel"("Channel_ID") )
tv_shows
How many radios are there?
SELECT count(*) FROM radio
CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") )
CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
List the transmitters of radios in ascending order of erp kw .
select transmitter from radio order by erp_kw asc
CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") )
CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
What are the names and original air dates of tv shows?
SELECT tv_show_name , Original_Airdate FROM tv_show
CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") )
CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
List the station names of city channels whose affiliation is not "ABC".
SELECT Station_name FROM city_channel WHERE Affiliation != "ABC"
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
Show the transmitters of radios whose ERP is bigger than 150 or smaller than 30.
SELECT Transmitter FROM radio WHERE ERP_kW > 150 OR ERP_kW < 30
CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") )
CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
What is the transmitter of the radio with the largest ERP_kW?
SELECT Transmitter FROM radio ORDER BY ERP_kW DESC LIMIT 1
CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") )
CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
What is the average ERP across all radios?
SELECT avg(ERP_kW) FROM radio
CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") )
CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
Show the different affiliations of city channels and the number of city channels with each affiliation.
SELECT Affiliation , COUNT(*) FROM city_channel GROUP BY Affiliation
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
Please show the most common affiliation for city channels.
SELECT Affiliation FROM city_channel GROUP BY Affiliation ORDER BY COUNT(*) DESC LIMIT 1
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
List the affiliations shared by more than three city channels.
SELECT Affiliation FROM city_channel GROUP BY Affiliation HAVING COUNT(*) > 3
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
Show the cities and station names of city channels in ascending alphabetical order of station name.
SELECT City , Station_name FROM city_channel ORDER BY Station_name ASC
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
Show the transmitters of radios and the cities of the channels they are associated with.
SELECT T3.Transmitter , T2.City FROM city_channel_radio AS T1 JOIN city_channel AS T2 ON T1.City_channel_ID = T2.ID JOIN radio AS T3 ON T1.Radio_ID = T3.Radio_ID
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
Show the transmitters of radios and the station names of the channels they are associated with in descending order of the ERP of the radios.
SELECT T3.Transmitter , T2.Station_name FROM city_channel_radio AS T1 JOIN city_channel AS T2 ON T1.City_channel_ID = T2.ID JOIN radio AS T3 ON T1.Radio_ID = T3.Radio_ID ORDER BY T3.ERP_kW DESC
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
Show the transmitters of the radios and the number of city channels they are associated with.
SELECT T2.Transmitter , COUNT(*) FROM city_channel_radio AS T1 JOIN radio AS T2 ON T1.Radio_ID = T2.Radio_ID GROUP BY T2.Transmitter
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
tv_shows
Show the distinct transmitters of radios that are not associated with any city channel.
SELECT Transmitter FROM radio WHERE Radio_ID NOT IN (SELECT Radio_ID FROM city_channel_radio)
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) )
CREATE TABLE "city_channel" ( "ID" int, "City" text, "Station_name" text, "Owned_Since" real, "Affiliation" text, PRIMARY KEY ("ID") ) CREATE TABLE "radio" ( "Radio_ID" int, "Transmitter" text, "Radio_MHz" text, "2FM_MHz" text, "RnaG_MHz" text, "Lyric_FM_MHz" text, "ERP_kW" text, PRIMARY KEY ("Radio_ID") ) CREATE TABLE "tv_show" ( "tv_show_ID" int, "tv_show_name" text, "Sub_tittle" text, "Next_show_name" text, "Original_Airdate" text, PRIMARY KEY ("tv_show_ID") ) CREATE TABLE "city_channel_radio" ( "City_channel_ID" int, "Radio_ID" int, "Is_online" bool, PRIMARY KEY ("City_channel_ID","Radio_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`Radio_ID`) REFERENCES `radio`(`Radio_ID`) ) CREATE TABLE "city_channel_tv_show" ( "City_channel_ID" int, "tv_show_ID" int, "Is_online" bool, "Is_free" bool, PRIMARY KEY ("City_channel_ID","tv_show_ID"), FOREIGN KEY (`City_channel_ID`) REFERENCES `city_channel`(`ID`), FOREIGN KEY (`tv_show_ID`) REFERENCES `tv_show`(`tv_show_ID`) )
vehicle_driver
What is the model of the vehicle with maximum top speed whose power is higher than 6000?
SELECT model FROM vehicle WHERE power > 6000 ORDER BY top_speed DESC LIMIT 1
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Of vehicles with power over 6000, return the model of the vehicle with the greatest top speed.
SELECT model FROM vehicle WHERE power > 6000 ORDER BY top_speed DESC LIMIT 1
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What are the names of the drivers who are citizens of the 'United States'?
SELECT name FROM driver WHERE citizenship = 'United States'
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the names of drivers with citizenship from the United States.
SELECT name FROM driver WHERE citizenship = 'United States'
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
How many vehicles has a driver driven at most, and what is the driver id of the driver who has driven this many vehicles?
SELECT count(*) , driver_id FROM vehicle_driver GROUP BY driver_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What is the id of the driver who has driven the most vehicles, and how many vehicles is this?
SELECT count(*) , driver_id FROM vehicle_driver GROUP BY driver_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What is the maximum and average power for the vehicles manufactured by 'Zhuzhou'?
SELECT max(power) , avg(power) FROM vehicle WHERE builder = 'Zhuzhou'
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the maximum and average power for the vehicles built by Zhuzhou.
SELECT max(power) , avg(power) FROM vehicle WHERE builder = 'Zhuzhou'
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What is the id of the vehicle driven for the least times for the vehicles ever used?
SELECT vehicle_id FROM vehicle_driver GROUP BY vehicle_id ORDER BY count(*) ASC LIMIT 1
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the id of the vehicle that has been driven the fewest times.
SELECT vehicle_id FROM vehicle_driver GROUP BY vehicle_id ORDER BY count(*) ASC LIMIT 1
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What is the top speed and power of the vehicle manufactured in the year of 1996?
SELECT top_speed , power FROM vehicle WHERE build_year = 1996
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the top speed and power of the vehicle that was built in the year 1996.
SELECT top_speed , power FROM vehicle WHERE build_year = 1996
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What are the build year, model name and builder of the vehicles?
SELECT build_year , model , builder FROM vehicle
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Give the build year, model, and builder of each vehicle.
SELECT build_year , model , builder FROM vehicle
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
How many drivers have driven vehicles built in 2012?
SELECT count(DISTINCT T1.driver_id) FROM vehicle_driver AS T1 JOIN vehicle AS T2 ON T1.vehicle_id = T2.vehicle_id WHERE T2.build_year = 2012
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Count the number of different drivers who have driven vehicles built in 2012.
SELECT count(DISTINCT T1.driver_id) FROM vehicle_driver AS T1 JOIN vehicle AS T2 ON T1.vehicle_id = T2.vehicle_id WHERE T2.build_year = 2012
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
How many drivers have raced in 'NASCAR'?
SELECT count(*) FROM driver WHERE Racing_Series = 'NASCAR'
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Count the number of drivers who have raced in NASCAR.
SELECT count(*) FROM driver WHERE Racing_Series = 'NASCAR'
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What is the average top speed of vehicles?
SELECT avg(top_speed) FROM vehicle
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the average top speed across all vehicles.
SELECT avg(top_speed) FROM vehicle
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What are the distinct driver names who have driven vehicles with power more than 5000 ?
select distinct t1.name from driver as t1 join vehicle_driver as t2 on t1.driver_id = t2.driver_id join vehicle as t3 on t2.vehicle_id = t3.vehicle_id where t3.power > 5000
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the names of drivers who have driven vehicles with power over 5000.
SELECT DISTINCT T1.Name FROM driver AS T1 JOIN vehicle_driver AS T2 ON T1.driver_id = T2.driver_id JOIN vehicle AS T3 ON T2.vehicle_id = T3.vehicle_id WHERE T3.power > 5000
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Which car models have total production larger than 100 or top speed higher than 150?
SELECT model FROM vehicle WHERE total_production > 100 OR top_speed > 150
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Give the models of cars that have a total production of over 100 or a top speed over 150.
SELECT model FROM vehicle WHERE total_production > 100 OR top_speed > 150
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What are the model names and build year of the cars with 'DJ' in its model name?
SELECT model , build_year FROM vehicle WHERE model LIKE '%DJ%'
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the model and build year of cars that include "DJ" in their model names.
SELECT model , build_year FROM vehicle WHERE model LIKE '%DJ%'
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What are the models which have not been driven by any drivers?
SELECT model FROM vehicle EXCEPT SELECT T1.model FROM vehicle AS T1 JOIN vehicle_driver AS T2 ON T1.vehicle_id = T2.vehicle_id
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the models of vehicles that have never been driven.
SELECT model FROM vehicle EXCEPT SELECT T1.model FROM vehicle AS T1 JOIN vehicle_driver AS T2 ON T1.vehicle_id = T2.vehicle_id
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What are the vehicle ids and models of the vehicle which have been driven by two drivers or been manufactured by 'Ziyang'.
SELECT T1.vehicle_id , T1.model FROM vehicle AS T1 JOIN vehicle_driver AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T2.vehicle_id HAVING count(*) = 2 OR T1.builder = 'Ziyang'
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the ids and models of vehicles that have been driven by exactly two drivers or built by Ziyang.
SELECT T1.vehicle_id , T1.model FROM vehicle AS T1 JOIN vehicle_driver AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T2.vehicle_id HAVING count(*) = 2 OR T1.builder = 'Ziyang'
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What are the vehicle ids and models which have been driven by more than 2 drivers or been driven by the driver named 'Jeff Gordon'?
SELECT T1.vehicle_id , T1.model FROM vehicle AS T1 JOIN vehicle_driver AS T2 ON T1.vehicle_id = T2.vehicle_id JOIN driver AS T3 ON T2.driver_id = T3.driver_id WHERE T3.name = 'Jeff Gordon' UNION SELECT T1.vehicle_id , T1.model FROM vehicle AS T1 JOIN vehicle_driver AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T2.vehicle_id HAVING count(*) > 2
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the ids and models of vehicles that have been driven by more than 2 drivers or been driven by the Jeff Gordon.
SELECT T1.vehicle_id , T1.model FROM vehicle AS T1 JOIN vehicle_driver AS T2 ON T1.vehicle_id = T2.vehicle_id JOIN driver AS T3 ON T2.driver_id = T3.driver_id WHERE T3.name = 'Jeff Gordon' UNION SELECT T1.vehicle_id , T1.model FROM vehicle AS T1 JOIN vehicle_driver AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T2.vehicle_id HAVING count(*) > 2
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
How many vehicles have maximum top speed?
SELECT count(*) FROM vehicle WHERE top_speed = (SELECT max(top_speed) FROM vehicle)
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Count the number of vehicles that have a top speed equal to the maximum across all vehicles.
SELECT count(*) FROM vehicle WHERE top_speed = (SELECT max(top_speed) FROM vehicle)
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Show all driver names in the alphabetical order.
SELECT name FROM driver ORDER BY name
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What are the names of drivers, returned in alphbetical order?
SELECT name FROM driver ORDER BY name
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
How many drivers have been racing in each racing series?
SELECT count(*) , racing_series FROM driver GROUP BY racing_series
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Count the number of drivers that have raced in each series.
SELECT count(*) , racing_series FROM driver GROUP BY racing_series
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
What are the name and citizenship of the drivers who have driven the vehicle model 'DJ1'?
SELECT T1.name , T1.citizenship FROM driver AS T1 JOIN vehicle_driver AS T2 ON T1.driver_id = T2.driver_id JOIN vehicle AS T3 ON T2.vehicle_id = T3.vehicle_id WHERE T3.model = 'DJ1'
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Return the names and citizenships of drivers who have driven the vehicle with the model 'DJ1'.
SELECT T1.name , T1.citizenship FROM driver AS T1 JOIN vehicle_driver AS T2 ON T1.driver_id = T2.driver_id JOIN vehicle AS T3 ON T2.vehicle_id = T3.vehicle_id WHERE T3.model = 'DJ1'
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
How many drivers have not driven any cars?
SELECT count(*) FROM driver WHERE driver_id NOT IN ( SELECT driver_id FROM vehicle_driver )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
vehicle_driver
Count the number of drivers who have not driven any vehicles.
SELECT count(*) FROM driver WHERE driver_id NOT IN ( SELECT driver_id FROM vehicle_driver )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
CREATE TABLE "vehicle" ( "Vehicle_ID" int, "Model" text, "Build_Year" text, "Top_Speed" int, "Power" int, "Builder" text, "Total_Production" text, PRIMARY KEY ("Vehicle_ID") ) CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Citizenship" text, "Racing_Series" text, PRIMARY KEY ("Driver_ID") ) CREATE TABLE "vehicle_driver" ( "Driver_ID" int, "Vehicle_ID" int, PRIMARY KEY ("Driver_ID","Vehicle_ID"), FOREIGN KEY ("Driver_ID") REFERENCES "driver"("Driver_ID"), FOREIGN KEY ("Vehicle_ID") REFERENCES "vehicle"("Vehicle_ID") )
online_exams
How many exams are there?
SELECT count(*) FROM Exams
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Students ( Student_ID INTEGER NOT NULL, First_Name VARCHAR(255), Middle_Name VARCHAR(255), Last_Name VARCHAR(255), Gender_MFU CHAR(1), Student_Address VARCHAR(255), Email_Adress VARCHAR(255), Cell_Mobile_Phone VARCHAR(255), Home_Phone VARCHAR(255), PRIMARY KEY (Student_ID) ) CREATE TABLE Questions ( Question_ID INTEGER NOT NULL, Type_of_Question_Code VARCHAR(15) NOT NULL, Question_Text VARCHAR(255), PRIMARY KEY (Question_ID) ) CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) ) CREATE TABLE Questions_in_Exams ( Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, PRIMARY KEY (Exam_ID, Question_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID), FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID) ) CREATE TABLE Valid_Answers ( Valid_Answer_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Valid_Answer_Text VARCHAR(255), PRIMARY KEY (Valid_Answer_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID) ) CREATE TABLE Student_Answers ( Student_Answer_ID INTEGER NOT NULL, Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Student_ID INTEGER NOT NULL, Date_of_Answer DATETIME, Comments VARCHAR(255), Satisfactory_YN VARCHAR(1), Student_Answer_Text VARCHAR(255), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID), FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID) ) CREATE TABLE Student_Assessments ( Student_Answer_ID VARCHAR(100) NOT NULL, Valid_Answer_ID INTEGER NOT NULL, Student_Answer_Text VARCHAR(255), Satisfactory_YN CHAR(1), Assessment VARCHAR(40), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID) )
online_exams
Count the number of exams.
SELECT count(*) FROM Exams
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Students ( Student_ID INTEGER NOT NULL, First_Name VARCHAR(255), Middle_Name VARCHAR(255), Last_Name VARCHAR(255), Gender_MFU CHAR(1), Student_Address VARCHAR(255), Email_Adress VARCHAR(255), Cell_Mobile_Phone VARCHAR(255), Home_Phone VARCHAR(255), PRIMARY KEY (Student_ID) ) CREATE TABLE Questions ( Question_ID INTEGER NOT NULL, Type_of_Question_Code VARCHAR(15) NOT NULL, Question_Text VARCHAR(255), PRIMARY KEY (Question_ID) ) CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) ) CREATE TABLE Questions_in_Exams ( Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, PRIMARY KEY (Exam_ID, Question_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID), FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID) ) CREATE TABLE Valid_Answers ( Valid_Answer_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Valid_Answer_Text VARCHAR(255), PRIMARY KEY (Valid_Answer_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID) ) CREATE TABLE Student_Answers ( Student_Answer_ID INTEGER NOT NULL, Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Student_ID INTEGER NOT NULL, Date_of_Answer DATETIME, Comments VARCHAR(255), Satisfactory_YN VARCHAR(1), Student_Answer_Text VARCHAR(255), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID), FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID) ) CREATE TABLE Student_Assessments ( Student_Answer_ID VARCHAR(100) NOT NULL, Valid_Answer_ID INTEGER NOT NULL, Student_Answer_Text VARCHAR(255), Satisfactory_YN CHAR(1), Assessment VARCHAR(40), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID) )
online_exams
List the distinct subject code of exams in ascending alphabetical order .
select distinct subject_code from exams order by subject_code asc
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Students ( Student_ID INTEGER NOT NULL, First_Name VARCHAR(255), Middle_Name VARCHAR(255), Last_Name VARCHAR(255), Gender_MFU CHAR(1), Student_Address VARCHAR(255), Email_Adress VARCHAR(255), Cell_Mobile_Phone VARCHAR(255), Home_Phone VARCHAR(255), PRIMARY KEY (Student_ID) ) CREATE TABLE Questions ( Question_ID INTEGER NOT NULL, Type_of_Question_Code VARCHAR(15) NOT NULL, Question_Text VARCHAR(255), PRIMARY KEY (Question_ID) ) CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) ) CREATE TABLE Questions_in_Exams ( Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, PRIMARY KEY (Exam_ID, Question_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID), FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID) ) CREATE TABLE Valid_Answers ( Valid_Answer_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Valid_Answer_Text VARCHAR(255), PRIMARY KEY (Valid_Answer_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID) ) CREATE TABLE Student_Answers ( Student_Answer_ID INTEGER NOT NULL, Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Student_ID INTEGER NOT NULL, Date_of_Answer DATETIME, Comments VARCHAR(255), Satisfactory_YN VARCHAR(1), Student_Answer_Text VARCHAR(255), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID), FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID) ) CREATE TABLE Student_Assessments ( Student_Answer_ID VARCHAR(100) NOT NULL, Valid_Answer_ID INTEGER NOT NULL, Student_Answer_Text VARCHAR(255), Satisfactory_YN CHAR(1), Assessment VARCHAR(40), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID) )
online_exams
Give me an alphabetically ordered list of the distinct subject code for exams.
SELECT DISTINCT Subject_Code FROM Exams ORDER BY Subject_Code
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Students ( Student_ID INTEGER NOT NULL, First_Name VARCHAR(255), Middle_Name VARCHAR(255), Last_Name VARCHAR(255), Gender_MFU CHAR(1), Student_Address VARCHAR(255), Email_Adress VARCHAR(255), Cell_Mobile_Phone VARCHAR(255), Home_Phone VARCHAR(255), PRIMARY KEY (Student_ID) ) CREATE TABLE Questions ( Question_ID INTEGER NOT NULL, Type_of_Question_Code VARCHAR(15) NOT NULL, Question_Text VARCHAR(255), PRIMARY KEY (Question_ID) ) CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) ) CREATE TABLE Questions_in_Exams ( Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, PRIMARY KEY (Exam_ID, Question_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID), FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID) ) CREATE TABLE Valid_Answers ( Valid_Answer_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Valid_Answer_Text VARCHAR(255), PRIMARY KEY (Valid_Answer_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID) ) CREATE TABLE Student_Answers ( Student_Answer_ID INTEGER NOT NULL, Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Student_ID INTEGER NOT NULL, Date_of_Answer DATETIME, Comments VARCHAR(255), Satisfactory_YN VARCHAR(1), Student_Answer_Text VARCHAR(255), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID), FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID) ) CREATE TABLE Student_Assessments ( Student_Answer_ID VARCHAR(100) NOT NULL, Valid_Answer_ID INTEGER NOT NULL, Student_Answer_Text VARCHAR(255), Satisfactory_YN CHAR(1), Assessment VARCHAR(40), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID) )
online_exams
What are the names and dates of the exams with subject code that is not "Database"?
SELECT Exam_Date , Exam_Name FROM Exams WHERE Subject_Code != 'Database'
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Students ( Student_ID INTEGER NOT NULL, First_Name VARCHAR(255), Middle_Name VARCHAR(255), Last_Name VARCHAR(255), Gender_MFU CHAR(1), Student_Address VARCHAR(255), Email_Adress VARCHAR(255), Cell_Mobile_Phone VARCHAR(255), Home_Phone VARCHAR(255), PRIMARY KEY (Student_ID) ) CREATE TABLE Questions ( Question_ID INTEGER NOT NULL, Type_of_Question_Code VARCHAR(15) NOT NULL, Question_Text VARCHAR(255), PRIMARY KEY (Question_ID) ) CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) ) CREATE TABLE Questions_in_Exams ( Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, PRIMARY KEY (Exam_ID, Question_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID), FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID) ) CREATE TABLE Valid_Answers ( Valid_Answer_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Valid_Answer_Text VARCHAR(255), PRIMARY KEY (Valid_Answer_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID) ) CREATE TABLE Student_Answers ( Student_Answer_ID INTEGER NOT NULL, Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Student_ID INTEGER NOT NULL, Date_of_Answer DATETIME, Comments VARCHAR(255), Satisfactory_YN VARCHAR(1), Student_Answer_Text VARCHAR(255), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID), FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID) ) CREATE TABLE Student_Assessments ( Student_Answer_ID VARCHAR(100) NOT NULL, Valid_Answer_ID INTEGER NOT NULL, Student_Answer_Text VARCHAR(255), Satisfactory_YN CHAR(1), Assessment VARCHAR(40), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID) )
online_exams
Find the exams whose subject code is not "Database". What are the exam dates and exam names?
SELECT Exam_Date , Exam_Name FROM Exams WHERE Subject_Code != 'Database'
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Students ( Student_ID INTEGER NOT NULL, First_Name VARCHAR(255), Middle_Name VARCHAR(255), Last_Name VARCHAR(255), Gender_MFU CHAR(1), Student_Address VARCHAR(255), Email_Adress VARCHAR(255), Cell_Mobile_Phone VARCHAR(255), Home_Phone VARCHAR(255), PRIMARY KEY (Student_ID) ) CREATE TABLE Questions ( Question_ID INTEGER NOT NULL, Type_of_Question_Code VARCHAR(15) NOT NULL, Question_Text VARCHAR(255), PRIMARY KEY (Question_ID) ) CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) ) CREATE TABLE Questions_in_Exams ( Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, PRIMARY KEY (Exam_ID, Question_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID), FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID) ) CREATE TABLE Valid_Answers ( Valid_Answer_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Valid_Answer_Text VARCHAR(255), PRIMARY KEY (Valid_Answer_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID) ) CREATE TABLE Student_Answers ( Student_Answer_ID INTEGER NOT NULL, Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Student_ID INTEGER NOT NULL, Date_of_Answer DATETIME, Comments VARCHAR(255), Satisfactory_YN VARCHAR(1), Student_Answer_Text VARCHAR(255), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID), FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID) ) CREATE TABLE Student_Assessments ( Student_Answer_ID VARCHAR(100) NOT NULL, Valid_Answer_ID INTEGER NOT NULL, Student_Answer_Text VARCHAR(255), Satisfactory_YN CHAR(1), Assessment VARCHAR(40), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID) )
online_exams
List the dates of the exams with subject code containing the word "data", in descending order of dates.
SELECT Exam_Date FROM Exams WHERE Subject_Code LIKE '%data%' ORDER BY Exam_Date DESC
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) )
CREATE TABLE Students ( Student_ID INTEGER NOT NULL, First_Name VARCHAR(255), Middle_Name VARCHAR(255), Last_Name VARCHAR(255), Gender_MFU CHAR(1), Student_Address VARCHAR(255), Email_Adress VARCHAR(255), Cell_Mobile_Phone VARCHAR(255), Home_Phone VARCHAR(255), PRIMARY KEY (Student_ID) ) CREATE TABLE Questions ( Question_ID INTEGER NOT NULL, Type_of_Question_Code VARCHAR(15) NOT NULL, Question_Text VARCHAR(255), PRIMARY KEY (Question_ID) ) CREATE TABLE Exams ( Exam_ID INTEGER NOT NULL, Subject_Code CHAR(15) NOT NULL, Exam_Date DATETIME, Exam_Name VARCHAR(255), PRIMARY KEY (Exam_ID) ) CREATE TABLE Questions_in_Exams ( Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, PRIMARY KEY (Exam_ID, Question_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID), FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID) ) CREATE TABLE Valid_Answers ( Valid_Answer_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Valid_Answer_Text VARCHAR(255), PRIMARY KEY (Valid_Answer_ID), FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID) ) CREATE TABLE Student_Answers ( Student_Answer_ID INTEGER NOT NULL, Exam_ID INTEGER NOT NULL, Question_ID INTEGER NOT NULL, Student_ID INTEGER NOT NULL, Date_of_Answer DATETIME, Comments VARCHAR(255), Satisfactory_YN VARCHAR(1), Student_Answer_Text VARCHAR(255), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID), FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID) ) CREATE TABLE Student_Assessments ( Student_Answer_ID VARCHAR(100) NOT NULL, Valid_Answer_ID INTEGER NOT NULL, Student_Answer_Text VARCHAR(255), Satisfactory_YN CHAR(1), Assessment VARCHAR(40), PRIMARY KEY (Student_Answer_ID), FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID) )