db_id
stringclasses 127
values | query
stringlengths 20
523
| question
stringlengths 16
224
| schema
stringclasses 127
values |
---|---|---|---|
products_for_hire | SELECT T1.customer_id , T1.first_name , count(*) FROM Customers AS T1 JOIN bookings AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id | How many bookings did each customer make? List the customer id, first name, and the count. | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT customer_id , sum(amount_paid) FROM Payments GROUP BY customer_id ORDER BY sum(amount_paid) DESC LIMIT 1 | What is the maximum total amount paid by a customer? List the customer id and amount. | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT T1.booking_id , T1.amount_of_refund FROM Bookings AS T1 JOIN Payments AS T2 ON T1.booking_id = T2.booking_id GROUP BY T1.booking_id ORDER BY count(*) DESC LIMIT 1 | What are the id and the amount of refund of the booking that incurred the most times of payments? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT product_id FROM products_booked GROUP BY product_id HAVING count(*) = 3 | What is the id of the product that is booked for 3 times? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT T2.product_description FROM products_booked AS T1 JOIN products_for_hire AS T2 ON T1.product_id = T2.product_id WHERE T1.booked_amount = 102.76 | What is the product description of the product booked with an amount of 102.76? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT T3.booking_start_date , T3.booking_end_date FROM Products_for_hire AS T1 JOIN products_booked AS T2 ON T1.product_id = T2.product_id JOIN bookings AS T3 ON T2.booking_id = T3.booking_id WHERE T1.product_name = 'Book collection A' | What are the start date and end date of the booking that has booked the product named 'Book collection A'? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT T2.product_name FROM view_product_availability AS T1 JOIN products_for_hire AS T2 ON T1.product_id = T2.product_id WHERE T1.available_yn = 1 | What are the names of products whose availability equals to 1? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT count(DISTINCT product_type_code) FROM products_for_hire | How many different product types are there? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT first_name , last_name , gender_mf FROM customers WHERE good_or_bad_customer = 'good' ORDER BY last_name | What are the first name, last name, and gender of all the good customers? Order by their last name. | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT avg(amount_due) FROM payments | What is the average amount due for all the payments? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT max(booked_count) , min(booked_count) , avg(booked_count) FROM products_booked | What are the maximum, minimum, and average booked count for the products booked? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT DISTINCT payment_type_code FROM payments | What are all the distinct payment types? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT daily_hire_cost FROM Products_for_hire WHERE product_name LIKE '%Book%' | What are the daily hire costs for the products with substring 'Book' in its name? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT count(*) FROM Products_for_hire WHERE product_id NOT IN ( SELECT product_id FROM products_booked WHERE booked_amount > 200 ) | How many products are never booked with amount higher than 200? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT T1.coupon_amount FROM Discount_Coupons AS T1 JOIN customers AS T2 ON T1.coupon_id = T2.coupon_id WHERE T2.good_or_bad_customer = 'good' INTERSECT SELECT T1.coupon_amount FROM Discount_Coupons AS T1 JOIN customers AS T2 ON T1.coupon_id = T2.coupon_id WHERE T2.good_or_bad_customer = 'bad' | What are the coupon amount of the coupons owned by both good and bad customers? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT payment_date FROM payments WHERE amount_paid > 300 OR payment_type_code = 'Check' | What are the payment date of the payment with amount paid higher than 300 or with payment type is 'Check' | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
products_for_hire | SELECT product_name , product_description FROM products_for_hire WHERE product_type_code = 'Cutlery' AND daily_hire_cost < 20 | What are the names and descriptions of the products that are of 'Cutlery' type and have daily hire cost lower than 20? | PRAGMA foreign_keys = ON;
CREATE TABLE `Discount_Coupons` (
`coupon_id` INTEGER PRIMARY KEY,
`date_issued` DATETIME,
`coupon_amount` DECIMAL(19,4)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`coupon_id` INTEGER NOT NULL,
`good_or_bad_customer` VARCHAR(4),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender_mf` VARCHAR(1),
`date_became_customer` DATETIME,
`date_last_hire` DATETIME,
FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` )
);
CREATE TABLE `Bookings` (
`booking_id` INTEGER PRIMARY KEY ,
`customer_id` INTEGER NOT NULL,
`booking_status_code` VARCHAR(10) NOT NULL,
`returned_damaged_yn` VARCHAR(40),
`booking_start_date` DATETIME,
`booking_end_date` DATETIME,
`count_hired` VARCHAR(40),
`amount_payable` DECIMAL(19,4),
`amount_of_discount` DECIMAL(19,4),
`amount_outstanding` DECIMAL(19,4),
`amount_of_refund` DECIMAL(19,4),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_for_Hire` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15) NOT NULL,
`daily_hire_cost` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_description` VARCHAR(255)
);
CREATE TABLE `Payments` (
`payment_id` INTEGER PRIMARY KEY,
`booking_id` INTEGER,
`customer_id` INTEGER NOT NULL,
`payment_type_code` VARCHAR(15) NOT NULL,
`amount_paid_in_full_yn` VARCHAR(1),
`payment_date` DATETIME,
`amount_due` DECIMAL(19,4),
`amount_paid` DECIMAL(19,4),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Products_Booked` (
`booking_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`returned_yn` VARCHAR(1),
`returned_late_yn` VARCHAR(1),
`booked_count` INTEGER,
`booked_amount` FLOAT NULL,
PRIMARY KEY (`booking_id`, `product_id`)
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
CREATE TABLE `View_Product_Availability` (
`product_id` INTEGER NOT NULL,
`booking_id` INTEGER NOT NULL,
`status_date` DATETIME PRIMARY KEY,
`available_yn` VARCHAR(1),
FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` )
);
INSERT INTO Discount_Coupons (`coupon_id`, `date_issued`, `coupon_amount`) VALUES (1, '2017-09-06 01:33:27', '500.0000')INSERT INTO Customers (`customer_id`, `coupon_id`, `good_or_bad_customer`, `first_name`, `last_name`, `gender_mf`, `date_became_customer`, `date_last_hire`) VALUES (1, 12, 'good', 'Geovany', 'Homenick', '0', '2017-10-20 12:13:17', '2018-02-27 18:55:26')INSERT INTO Bookings (`booking_id`, `customer_id`, `booking_status_code`, `returned_damaged_yn`, `booking_start_date`, `booking_end_date`, `count_hired`, `amount_payable`, `amount_of_discount`, `amount_outstanding`, `amount_of_refund`) VALUES (1, 7, 'Provisional', '1', '2016-12-07 23:39:17', '2018-02-01 16:39:13', '298', '214.3900', '71.4500', '28.2200', '179.1400')INSERT INTO Products_for_Hire (`product_id`, `product_type_code`, `daily_hire_cost`, `product_name`, `product_description`) VALUES (1, 'Cutlery', '26.1500', 'Book collection C', 'Anna Karenina')INSERT INTO Payments (`payment_id`, `booking_id`, `customer_id`, `payment_type_code`, `amount_paid_in_full_yn`, `payment_date`, `amount_due`, `amount_paid`) VALUES (1, 6, 15, 'Check', '1', '2018-03-09 16:28:00', '369.5200', '206.2700')INSERT INTO Products_Booked (`booking_id`, `product_id`, `returned_yn`, `returned_late_yn`, `booked_count`, `booked_amount`) VALUES (4, 1, '1', '1', 5, '309.73')INSERT INTO View_Product_Availability (`product_id`, `booking_id`, `status_date`, `available_yn`) VALUES (1, 5, '2018-03-18 05:25:55', '1') |
phone_market | SELECT count(*) FROM phone | How many phones are there? |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT Name FROM phone ORDER BY Price ASC | List the names of phones in ascending order of price. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT Memory_in_G , Carrier FROM phone | What are the memories and carriers of phones? |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT DISTINCT Carrier FROM phone WHERE Memory_in_G > 32 | List the distinct carriers of phones with memories bigger than 32. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT Name FROM phone WHERE Carrier = "Sprint" OR Carrier = "TMobile" | Show the names of phones with carrier either "Sprint" or "TMobile". |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT Carrier FROM phone ORDER BY Price DESC LIMIT 1 | What is the carrier of the most expensive phone? |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT Carrier , COUNT(*) FROM phone GROUP BY Carrier | Show different carriers of phones together with the number of phones with each carrier. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT Carrier FROM phone GROUP BY Carrier ORDER BY COUNT(*) DESC LIMIT 1 | Show the most frequently used carrier of the phones. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT Carrier FROM phone WHERE Memory_in_G < 32 INTERSECT SELECT Carrier FROM phone WHERE Memory_in_G > 64 | Show the carriers that have both phones with memory smaller than 32 and phones with memory bigger than 64. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT T3.Name , T2.District FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID = T3.Phone_ID | Show the names of phones and the districts of markets they are on. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT T3.Name , T2.District FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID = T3.Phone_ID ORDER BY T2.Ranking | Show the names of phones and the districts of markets they are on, in ascending order of the ranking of the market. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT T3.Name FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID = T3.Phone_ID WHERE T2.Num_of_shops > 50 | Show the names of phones that are on market with number of shops greater than 50. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT T2.Name , sum(T1.Num_of_stock) FROM phone_market AS T1 JOIN phone AS T2 ON T1.Phone_ID = T2.Phone_ID GROUP BY T2.Name | For each phone, show its names and total number of stocks. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT T2.Name FROM phone_market AS T1 JOIN phone AS T2 ON T1.Phone_ID = T2.Phone_ID GROUP BY T2.Name HAVING sum(T1.Num_of_stock) >= 2000 ORDER BY sum(T1.Num_of_stock) DESC | Show the names of phones that have total number of stocks bigger than 2000, in descending order of the total number of stocks. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
phone_market | SELECT Name FROM phone WHERE Phone_id NOT IN (SELECT Phone_ID FROM phone_market) | List the names of phones that are not on any market. |
PRAGMA foreign_keys = ON;
CREATE TABLE "phone" (
"Name" text,
"Phone_ID" int,
"Memory_in_G" int,
"Carrier" text,
"Price" real,
PRIMARY KEY ("Phone_ID")
);
CREATE TABLE "market" (
"Market_ID" int,
"District" text,
"Num_of_employees" int,
"Num_of_shops" real,
"Ranking" int,
PRIMARY KEY ("Market_ID")
);
CREATE TABLE "phone_market" (
"Market_ID" int,
"Phone_ID" text,
"Num_of_stock" int,
PRIMARY KEY ("Market_ID","Phone_ID"),
FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"),
FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID")
);
INSERT INTO "phone" VALUES ("IPhone 5s","1","32","Sprint","320");
INSERT INTO "market" VALUES (1,"Alberta","1966","40","1");
INSERT INTO "phone_market" VALUES (1,1,2232);
|
gas_company | SELECT count(*) FROM company | How many gas companies are there? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT count(*) FROM company | What is the total number of companies? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT company , rank FROM company ORDER BY Sales_billion DESC | List the company name and rank for all companies in the decreasing order of their sales. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT company , rank FROM company ORDER BY Sales_billion DESC | What is the name and rank of every company ordered by descending number of sales? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT company , main_industry FROM company WHERE headquarters != 'USA' | Show the company name and the main industry for all companies whose headquarters are not from USA. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT company , main_industry FROM company WHERE headquarters != 'USA' | What are the companies and main industries of all companies that are not headquartered in the United States? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT company , headquarters FROM company ORDER BY market_value DESC | Show all company names and headquarters in the descending order of market value. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT company , headquarters FROM company ORDER BY market_value DESC | What are the names and headquarters of all companies ordered by descending market value? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT min(market_value) , max(market_value) , avg(market_value) FROM company | Show minimum, maximum, and average market value for all companies. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT min(market_value) , max(market_value) , avg(market_value) FROM company | What is the minimum, maximum, and average market value for every company? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT DISTINCT main_industry FROM company | Show all main industry for all companies. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT DISTINCT main_industry FROM company | What are the different main industries for all companies? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT headquarters , count(*) FROM company GROUP BY headquarters | List all headquarters and the number of companies in each headquarter. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT headquarters , count(*) FROM company GROUP BY headquarters | For each headquarter, what are the headquarter and how many companies are centered there? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT main_industry , sum(market_value) FROM company GROUP BY main_industry | Show all main industry and total market value in each industry. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT main_industry , sum(market_value) FROM company GROUP BY main_industry | What are the main indstries and total market value for each industry? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT main_industry , count(*) FROM company GROUP BY main_industry ORDER BY sum(market_value) DESC LIMIT 1 | List the main industry with highest total market value and its number of companies. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT main_industry , count(*) FROM company GROUP BY main_industry ORDER BY sum(market_value) DESC LIMIT 1 | For each main industry, what is the total number of companies for the industry with the highest total market value? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT headquarters FROM company WHERE main_industry = 'Banking' GROUP BY headquarters HAVING count(*) >= 2 | Show headquarters with at least two companies in the banking industry. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT headquarters FROM company WHERE main_industry = 'Banking' GROUP BY headquarters HAVING count(*) >= 2 | What are the headquarters with at least two companies in the banking industry? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT station_id , LOCATION , manager_name FROM gas_station ORDER BY open_year | Show gas station id, location, and manager_name for all gas stations ordered by open year. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT station_id , LOCATION , manager_name FROM gas_station ORDER BY open_year | What are the gas station ids, locations, and manager names for the gas stations ordered by opening year? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT count(*) FROM gas_station WHERE open_year BETWEEN 2000 AND 2005 | How many gas station are opened between 2000 and 2005? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT count(*) FROM gas_station WHERE open_year BETWEEN 2000 AND 2005 | What is the total number of gas stations that opened between 2000 and 2005? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT LOCATION , count(*) FROM gas_station GROUP BY LOCATION ORDER BY count(*) | Show all locations and the number of gas stations in each location ordered by the count. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT LOCATION , count(*) FROM gas_station GROUP BY LOCATION ORDER BY count(*) | For each location, how many gas stations are there in order? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT headquarters FROM company WHERE main_industry = 'Banking' INTERSECT SELECT headquarters FROM company WHERE main_industry = 'Oil and gas' | Show all headquarters with both a company in banking industry and a company in Oil and gas. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT headquarters FROM company WHERE main_industry = 'Banking' INTERSECT SELECT headquarters FROM company WHERE main_industry = 'Oil and gas' | What are the headquarters that have both a company in the banking and 'oil and gas' industries? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT headquarters FROM company EXCEPT SELECT headquarters FROM company WHERE main_industry = 'Banking' | Show all headquarters without a company in banking industry. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT headquarters FROM company EXCEPT SELECT headquarters FROM company WHERE main_industry = 'Banking' | What are the headquarters without companies that are in the banking industry? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT T2.company , count(*) FROM station_company AS T1 JOIN company AS T2 ON T1.company_id = T2.company_id GROUP BY T1.company_id | Show the company name with the number of gas station. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT T2.company , count(*) FROM station_company AS T1 JOIN company AS T2 ON T1.company_id = T2.company_id GROUP BY T1.company_id | For each company id, what are the companies and how many gas stations does each one operate? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT company , main_industry FROM company WHERE company_id NOT IN (SELECT company_id FROM station_company) | Show company name and main industry without a gas station. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT company , main_industry FROM company WHERE company_id NOT IN (SELECT company_id FROM station_company) | What are the main industries of the companies without gas stations and what are the companies? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT T3.manager_name FROM station_company AS T1 JOIN company AS T2 ON T1.company_id = T2.company_id JOIN gas_station AS T3 ON T1.station_id = T3.station_id WHERE T2.company = 'ExxonMobil' | Show the manager name for gas stations belonging to the ExxonMobil company. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT T3.manager_name FROM station_company AS T1 JOIN company AS T2 ON T1.company_id = T2.company_id JOIN gas_station AS T3 ON T1.station_id = T3.station_id WHERE T2.company = 'ExxonMobil' | What are the names of the managers for gas stations that are operated by the ExxonMobil company? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT T3.location FROM station_company AS T1 JOIN company AS T2 ON T1.company_id = T2.company_id JOIN gas_station AS T3 ON T1.station_id = T3.station_id WHERE T2.market_value > 100 | Show all locations where a gas station for company with market value greater than 100 is located. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT T3.location FROM station_company AS T1 JOIN company AS T2 ON T1.company_id = T2.company_id JOIN gas_station AS T3 ON T1.station_id = T3.station_id WHERE T2.market_value > 100 | What are the locations that have gas stations owned by a company with a market value greater than 100? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT manager_name FROM gas_station WHERE open_year > 2000 GROUP BY manager_name ORDER BY count(*) DESC LIMIT 1 | Show the manager name with most number of gas stations opened after 2000. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT manager_name FROM gas_station WHERE open_year > 2000 GROUP BY manager_name ORDER BY count(*) DESC LIMIT 1 | What is the name of the manager with the most gas stations that opened after 2000? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT LOCATION FROM gas_station ORDER BY open_year | order all gas station locations by the opening year. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT LOCATION FROM gas_station ORDER BY open_year | What are the locations of all the gas stations ordered by opening year? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT rank , company , market_value FROM company WHERE main_industry = 'Banking' ORDER BY sales_billion , profits_billion | find the rank, company names, market values of the companies in the banking industry order by their sales and profits in billion. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT rank , company , market_value FROM company WHERE main_industry = 'Banking' ORDER BY sales_billion , profits_billion | What is the rank, company, and market value of every comapny in the banking industry ordered by sales and profits? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT T3.location , T3.Representative_Name FROM station_company AS T1 JOIN company AS T2 ON T1.company_id = T2.company_id JOIN gas_station AS T3 ON T1.station_id = T3.station_id ORDER BY T2.Assets_billion DESC LIMIT 3 | find the location and Representative name of the gas stations owned by the companies with top 3 Asset amounts. |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
gas_company | SELECT T3.location , T3.Representative_Name FROM station_company AS T1 JOIN company AS T2 ON T1.company_id = T2.company_id JOIN gas_station AS T3 ON T1.station_id = T3.station_id ORDER BY T2.Assets_billion DESC LIMIT 3 | What are the locations and representatives' names of the gas stations owned by the companies with the 3 largest amounts of assets? |
PRAGMA foreign_keys = ON;
CREATE TABLE "company" (
"Company_ID" int,
"Rank" int,
"Company" text,
"Headquarters" text,
"Main_Industry" text,
"Sales_billion" real,
"Profits_billion" real,
"Assets_billion" real,
"Market_Value" real,
PRIMARY KEY ("Company_ID")
);
CREATE TABLE "gas_station" (
"Station_ID" int,
"Open_Year" int,
"Location" text,
"Manager_Name" text,
"Vice_Manager_Name" text,
"Representative_Name" text,
PRIMARY KEY ("Station_ID")
);
CREATE TABLE "station_company" (
"Station_ID" int,
"Company_ID" int,
"Rank_of_the_Year" int,
PRIMARY KEY ("Station_ID","Company_ID"),
FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`),
FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`)
);
INSERT INTO "company" VALUES (1,"1","ExxonMobil","USA","Oil and gas","433.5","41.1","331.1","407.4");
INSERT INTO "gas_station" VALUES (1,"1998","Herne Hill","BrianWingrave","Russell Denman","Clive Burr");
INSERT INTO "station_company" VALUES (11,1,1);
|
party_people | SELECT count(*) FROM region | How many regions do we have? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT count(*) FROM region | Count the number of regions. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT DISTINCT region_name FROM region ORDER BY Label | Show all distinct region names ordered by their labels. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT DISTINCT region_name FROM region ORDER BY Label | What are the different region names, ordered by labels? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT count(DISTINCT party_name) FROM party | How many parties do we have? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT count(DISTINCT party_name) FROM party | Count the number of different parties. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT minister , took_office , left_office FROM party ORDER BY left_office | Show the ministers and the time they took and left office, listed by the time they left office. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT minister , took_office , left_office FROM party ORDER BY left_office | Who are the ministers, when did they take office, and when did they leave office, ordered by when they left office? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT minister FROM party WHERE took_office > 1961 OR took_office < 1959 | Show the minister who took office after 1961 or before 1959. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT minister FROM party WHERE took_office > 1961 OR took_office < 1959 | Who are the ministers who took office after 1961 or before 1959? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT minister FROM party WHERE party_name != 'Progress Party' | Show all ministers who do not belong to Progress Party. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT minister FROM party WHERE party_name != 'Progress Party' | Which ministers are not a part of the Progress Party? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT minister , party_name FROM party ORDER BY took_office DESC | Show all ministers and parties they belong to in descending order of the time they took office. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT minister , party_name FROM party ORDER BY took_office DESC | Who are the ministers and what parties do they belong to, listed descending by the times they took office? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT minister FROM party ORDER BY left_office DESC LIMIT 1 | Return the minister who left office at the latest time. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT minister FROM party ORDER BY left_office DESC LIMIT 1 | Which minister left office the latest? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT T1.member_name , T2.party_name FROM Member AS T1 JOIN party AS T2 ON T1.party_id = T2.party_id | List member names and their party names. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT T1.member_name , T2.party_name FROM Member AS T1 JOIN party AS T2 ON T1.party_id = T2.party_id | What are the names of members and their corresponding parties? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT T2.party_name , count(*) FROM Member AS T1 JOIN party AS T2 ON T1.party_id = T2.party_id GROUP BY T1.party_id | Show all party names and the number of members in each party. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT T2.party_name , count(*) FROM Member AS T1 JOIN party AS T2 ON T1.party_id = T2.party_id GROUP BY T1.party_id | How many members are in each party? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT T2.party_name FROM Member AS T1 JOIN party AS T2 ON T1.party_id = T2.party_id GROUP BY T1.party_id ORDER BY count(*) DESC LIMIT 1 | What is the name of party with most number of members? |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
party_people | SELECT T2.party_name FROM Member AS T1 JOIN party AS T2 ON T1.party_id = T2.party_id GROUP BY T1.party_id ORDER BY count(*) DESC LIMIT 1 | Return the name of the party with the most members. |
PRAGMA foreign_keys = ON;
CREATE TABLE "region" (
"Region_ID" int,
"Region_name" text,
"Date" text,
"Label" text,
"Format" text,
"Catalogue" text,
PRIMARY KEY ("Region_ID")
);
CREATE TABLE "party" (
"Party_ID" int,
"Minister" text,
"Took_office" text,
"Left_office" text,
"Region_ID" int,
"Party_name" text,
PRIMARY KEY ("Party_ID"),
FOREIGN KEY (`Region_ID`) REFERENCES `region`(`Region_ID`)
);
CREATE TABLE "member" (
"Member_ID" int,
"Member_Name" text,
"Party_ID" text,
"In_office" text,
PRIMARY KEY ("Member_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`)
);
CREATE TABLE "party_events" (
"Event_ID" int,
"Event_Name" text,
"Party_ID" int,
"Member_in_charge_ID" int,
PRIMARY KEY ("Event_ID"),
FOREIGN KEY (`Party_ID`) REFERENCES `party`(`Party_ID`),
FOREIGN KEY (`Member_in_charge_ID`) REFERENCES `member`(`Member_ID`)
);
INSERT INTO "region" VALUES (1,"United Kingdom","1 July 2002","Parlophone","CD","540 3622");
INSERT INTO "party" VALUES ("1","Dr. Kwame Nkrumah (MP)","1957","1958",1,"Convention Peoples Party")INSERT INTO "member" VALUES (1,"Hon Tony Abbott",3,"1994–present");
INSERT INTO "party_events" VALUES (1,"Annaual Meeting", 1,4);
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.