db_id
stringclasses
127 values
query
stringlengths
20
523
question
stringlengths
16
224
schema
stringclasses
127 values
customers_card_transactions
SELECT customer_id , customer_first_name FROM Customers EXCEPT SELECT T1.customer_id , T2.customer_first_name FROM Customers_cards AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE card_type_code = "Credit"
Show the customer ids and firstname without a credit card.
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT customer_id , customer_first_name FROM Customers EXCEPT SELECT T1.customer_id , T2.customer_first_name FROM Customers_cards AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE card_type_code = "Credit"
What are the ids and first names of customers who do not hold a credit card?
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT DISTINCT card_type_code FROM Customers_Cards
Show all card type codes.
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT DISTINCT card_type_code FROM Customers_Cards
What are the different card type codes?
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT count(DISTINCT card_type_code) FROM Customers_Cards
Show the number of card types.
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT count(DISTINCT card_type_code) FROM Customers_Cards
How many different card types are there?
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT DISTINCT transaction_type FROM Financial_Transactions
Show all transaction types.
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT DISTINCT transaction_type FROM Financial_Transactions
What are the different types of transactions?
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT count(DISTINCT transaction_type) FROM Financial_Transactions
Show the number of transaction types.
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT count(DISTINCT transaction_type) FROM Financial_Transactions
How many different types of transactions are there?
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT avg(transaction_amount) , sum(transaction_amount) FROM Financial_transactions
What is the average and total transaction amount?
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT avg(transaction_amount) , sum(transaction_amount) FROM Financial_transactions
Return the average transaction amount, as well as the total amount of all transactions.
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT T2.card_type_code , count(*) FROM Financial_transactions AS T1 JOIN Customers_cards AS T2 ON T1.card_id = T2.card_id GROUP BY T2.card_type_code
Show the card type codes and the number of transactions.
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT T2.card_type_code , count(*) FROM Financial_transactions AS T1 JOIN Customers_cards AS T2 ON T1.card_id = T2.card_id GROUP BY T2.card_type_code
What are the different card types, and how many transactions have been made with each?
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT transaction_type , count(*) FROM Financial_transactions GROUP BY transaction_type
Show the transaction type and the number of transactions.
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT transaction_type , count(*) FROM Financial_transactions GROUP BY transaction_type
What are the different transaction types, and how many transactions of each have taken place?
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT transaction_type FROM Financial_transactions GROUP BY transaction_type ORDER BY sum(transaction_amount) DESC LIMIT 1
What is the transaction type that has processed the greatest total amount in transactions?
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT transaction_type FROM Financial_transactions GROUP BY transaction_type ORDER BY sum(transaction_amount) DESC LIMIT 1
Return the type of transaction with the highest total amount.
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT account_id , count(*) FROM Financial_transactions GROUP BY account_id
Show the account id and the number of transactions for each account
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
customers_card_transactions
SELECT account_id , count(*) FROM Financial_transactions GROUP BY account_id
What are the different account ids that have made financial transactions, as well as how many transactions correspond to each?
CREATE TABLE `Accounts` ( `account_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `account_name` VARCHAR(50), `other_account_details` VARCHAR(255) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_first_name` VARCHAR(20), `customer_last_name` VARCHAR(20), `customer_address` VARCHAR(255), `customer_phone` VARCHAR(255), `customer_email` VARCHAR(255), `other_customer_details` VARCHAR(255) ); CREATE TABLE `Customers_Cards` ( `card_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `card_type_code` VARCHAR(15) NOT NULL, `card_number` VARCHAR(80), `date_valid_from` DATETIME, `date_valid_to` DATETIME, `other_card_details` VARCHAR(255) ); CREATE TABLE `Financial_Transactions` ( `transaction_id` INTEGER NOT NULL , `previous_transaction_id` INTEGER, `account_id` INTEGER NOT NULL, `card_id` INTEGER NOT NULL, `transaction_type` VARCHAR(15) NOT NULL, `transaction_date` DATETIME, `transaction_amount` DOUBLE NULL, `transaction_comment` VARCHAR(255), `other_transaction_details` VARCHAR(255), FOREIGN KEY (`card_id` ) REFERENCES `Customers_Cards`(`card_id` ), FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` ) ); INSERT INTO Accounts (`account_id`, `customer_id`, `account_name`, `other_account_details`) VALUES (1, 6, '338', 'Regular') INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_last_name`, `customer_address`, `customer_phone`, `customer_email`, `other_customer_details`) VALUES (1, 'Aniyah', 'Feest', '55975 Theodore Estates INSERT INTO Customers_Cards (`card_id`, `customer_id`, `card_type_code`, `card_number`, `date_valid_from`, `date_valid_to`, `other_card_details`) VALUES (1, 14, 'Credit', '4560596484842', '2011-04-17 09:05:28', '2018-03-07 17:06:19', '5567915676420343') INSERT INTO Financial_Transactions (`transaction_id`, `previous_transaction_id`, `account_id`, `card_id`, `transaction_type`, `transaction_date`, `transaction_amount`, `transaction_comment`, `other_transaction_details`) VALUES (1, 925, 15, 1, 'Payment', '2018-03-24 06:41:41', '1701.23', NULL, NULL)
race_track
SELECT count(*) FROM track
How many tracks do we have?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT count(*) FROM track
Count the number of tracks.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name , LOCATION FROM track
Show the name and location for all tracks.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name , LOCATION FROM track
What are the names and locations of all tracks?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name , seating FROM track WHERE year_opened > 2000 ORDER BY seating
Show names and seatings, ordered by seating for all tracks opened after 2000.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name , seating FROM track WHERE year_opened > 2000 ORDER BY seating
What are the names and seatings for all tracks opened after 2000, ordered by seating?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name , LOCATION , seating FROM track ORDER BY year_opened DESC LIMIT 1
What is the name, location and seating for the most recently opened track?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name , LOCATION , seating FROM track ORDER BY year_opened DESC LIMIT 1
Return the name, location, and seating of the track that was opened in the most recent year.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT min(seating) , max(seating) , avg(seating) FROM track
What is the minimum, maximum, and average seating for all tracks.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT min(seating) , max(seating) , avg(seating) FROM track
Return the minimum, maximum, and average seating across all tracks.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name , LOCATION , year_opened FROM track WHERE seating > (SELECT avg(seating) FROM track)
Show the name, location, open year for all tracks with a seating higher than the average.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name , LOCATION , year_opened FROM track WHERE seating > (SELECT avg(seating) FROM track)
What are the names, locations, and years of opening for tracks with seating higher than average?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT DISTINCT LOCATION FROM track
What are distinct locations where tracks are located?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT DISTINCT LOCATION FROM track
Give the different locations of tracks.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT count(*) FROM race
How many races are there?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT count(*) FROM race
Count the number of races.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT DISTINCT CLASS FROM race
What are the distinct classes that races can have?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT DISTINCT CLASS FROM race
Return the different classes of races.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name , CLASS , date FROM race
Show name, class, and date for all races.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name , CLASS , date FROM race
What are the names, classes, and dates for all races?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT CLASS , count(*) FROM race GROUP BY CLASS
Show the race class and number of races in each class.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT CLASS , count(*) FROM race GROUP BY CLASS
What are the different classes of races, and how many races correspond to each?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT CLASS FROM race GROUP BY CLASS ORDER BY count(*) DESC LIMIT 1
What is the race class with most number of races.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT CLASS FROM race GROUP BY CLASS ORDER BY count(*) DESC LIMIT 1
Give the class of races that is most common.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT CLASS FROM race GROUP BY CLASS HAVING count(*) >= 2
List the race class with at least two races.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT CLASS FROM race GROUP BY CLASS HAVING count(*) >= 2
What are the classes of races that have two or more corresponding races?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name FROM track EXCEPT SELECT T2.name FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id WHERE T1.class = 'GT'
What are the names for tracks without a race in class 'GT'.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name FROM track EXCEPT SELECT T2.name FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id WHERE T1.class = 'GT'
Give the names of tracks that do not have a race in the class 'GT'.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name FROM track WHERE track_id NOT IN (SELECT track_id FROM race)
Show all track names that have had no races.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT name FROM track WHERE track_id NOT IN (SELECT track_id FROM race)
Return the names of tracks that have no had any races.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT year_opened FROM track WHERE seating BETWEEN 4000 AND 5000
Show year where a track with a seating at least 5000 opened and a track with seating no more than 4000 opened.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT year_opened FROM track WHERE seating BETWEEN 4000 AND 5000
What are the years of opening for tracks with seating between 4000 and 5000?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT T2.name , count(*) FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id GROUP BY T1.track_id
Show the name of track and the number of races in each track.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT T2.name , count(*) FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id GROUP BY T1.track_id
What are the names of different tracks, and how many races has each had?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT T2.name FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id GROUP BY T1.track_id ORDER BY count(*) DESC LIMIT 1
Show the name of track with most number of races.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT T2.name FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id GROUP BY T1.track_id ORDER BY count(*) DESC LIMIT 1
What is the name of the track that has had the greatest number of races?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT T1.name , T1.date , T2.name FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id
Show the name and date for each race and its track name.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT T1.name , T1.date , T2.name FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id
What are the names and dates of races, and the names of the tracks where they are held?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT T2.name , T2.location FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id GROUP BY T1.track_id HAVING count(*) = 1
Show the name and location of track with 1 race.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT T2.name , T2.location FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id GROUP BY T1.track_id HAVING count(*) = 1
What are the names and locations of tracks that have had exactly 1 race?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT LOCATION FROM track WHERE seating > 90000 INTERSECT SELECT LOCATION FROM track WHERE seating < 70000
Find the locations where have both tracks with more than 90000 seats and tracks with less than 70000 seats.
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
race_track
SELECT LOCATION FROM track WHERE seating > 90000 INTERSECT SELECT LOCATION FROM track WHERE seating < 70000
What are the locations that have both tracks with more than 90000 seats, and tracks with fewer than 70000 seats?
CREATE TABLE "race" ( "Race_ID" int, "Name" text, "Class" text, "Date" text, "Track_ID" text, PRIMARY KEY ("Race_ID"), FOREIGN KEY ("Track_ID") REFERENCES "track"("Track_ID") ); CREATE TABLE "track" ( "Track_ID" int, "Name" text, "Location" text, "Seating" real, "Year_Opened" real, PRIMARY KEY ("Track_ID") ); INSERT INTO "track" VALUES (1,"Auto Club Speedway","Fontana, CA","92000","1997"); INSERT INTO "race" VALUES (1,"Rolex 24 At Daytona","DP/GT","January 26 January 27",1);
coffee_shop
SELECT count(*) FROM member WHERE Membership_card = 'Black'
How many members have the black membership card?
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT count(*) , address FROM member GROUP BY address
Find the number of members living in each address.
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT name FROM member WHERE address = 'Harford' OR address = 'Waterbury'
Give me the names of members whose address is in Harford or Waterbury.
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT name , member_id FROM member WHERE Membership_card = 'Black' OR age < 30
Find the ids and names of members who are under age 30 or with black membership card.
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT Time_of_purchase , age , address FROM member ORDER BY Time_of_purchase
Find the purchase time, age and address of each member, and show the results in the order of purchase time.
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT Membership_card FROM member GROUP BY Membership_card HAVING count(*) > 5
Which membership card has more than 5 members?
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT address FROM member WHERE age < 30 INTERSECT SELECT address FROM member WHERE age > 40
Which address has both members younger than 30 and members older than 40?
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT membership_card FROM member WHERE address = 'Hartford' INTERSECT SELECT membership_card FROM member WHERE address = 'Waterbury'
What is the membership card held by both members living in Hartford and ones living in Waterbury address?
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT count(*) FROM member WHERE address != 'Hartford'
How many members are not living in Hartford?
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT address FROM member EXCEPT SELECT address FROM member WHERE Membership_card = 'Black'
Which address do not have any member with the black membership card?
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT address FROM shop ORDER BY open_year
Show the shop addresses ordered by their opening year.
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT avg(num_of_staff) , avg(score) FROM shop
What are the average score and average staff number of all shops?
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT shop_id , address FROM shop WHERE score < (SELECT avg(score) FROM shop)
Find the id and address of the shops whose score is below the average score.
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT address , num_of_staff FROM shop WHERE shop_id NOT IN (SELECT shop_id FROM happy_hour)
Find the address and staff number of the shops that do not have any happy hour.
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT t1.address , t1.shop_id FROM shop AS t1 JOIN happy_hour AS t2 ON t1.shop_id = t2.shop_id WHERE MONTH = 'May'
What are the id and address of the shops which have a happy hour in May?
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT shop_id , count(*) FROM happy_hour GROUP BY shop_id ORDER BY count(*) DESC LIMIT 1
which shop has happy hour most frequently? List its id and number of happy hours.
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT MONTH FROM happy_hour GROUP BY MONTH ORDER BY count(*) DESC LIMIT 1
Which month has the most happy hours?
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
coffee_shop
SELECT MONTH FROM happy_hour GROUP BY MONTH HAVING count(*) > 2
Which months have more than 2 happy hours?
CREATE TABLE "shop" ( "Shop_ID" int, "Address" text, "Num_of_staff" text, "Score" real, "Open_Year" text, PRIMARY KEY ("Shop_ID") ); CREATE TABLE "member" ( "Member_ID" int, "Name" text, "Membership_card" text, "Age" int, "Time_of_purchase" int, "Level_of_membership" int, "Address" text, PRIMARY KEY ("Member_ID") ); CREATE TABLE "happy_hour" ( "HH_ID" int, "Shop_ID" int, "Month" text, "Num_of_shaff_in_charge" int, PRIMARY KEY ("HH_ID","Shop_ID","Month"), FOREIGN KEY ("Shop_ID") REFERENCES `shop`("Shop_ID") ); CREATE TABLE "happy_hour_member" ( "HH_ID" int, "Member_ID" int, "Total_amount" real, PRIMARY KEY ("HH_ID","Member_ID"), FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID") ); INSERT INTO "shop" VALUES ("1","1200 Main Street","13","42","2010"); INSERT INTO "member" VALUES (1,"Ashby, Lazale","Black","29","18","5","Hartford"); INSERT INTO "happy_hour" VALUES (1,1,"May",10); INSERT INTO "happy_hour_member" VALUES (1,3,20.90);
insurance_fnol
SELECT customer_phone FROM available_policies
Find all the phone numbers.
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT customer_phone FROM available_policies
What are all the phone numbers?
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT customer_phone FROM available_policies WHERE policy_type_code = "Life Insurance"
What are the customer phone numbers under the policy "Life Insurance"?
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT customer_phone FROM available_policies WHERE policy_type_code = "Life Insurance"
What are the phone numbers of customers using the policy with the code "Life Insurance"?
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT policy_type_code FROM available_policies GROUP BY policy_type_code ORDER BY count(*) DESC LIMIT 1
Which policy type has the most records in the database?
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT policy_type_code FROM available_policies GROUP BY policy_type_code ORDER BY count(*) DESC LIMIT 1
Which policy type appears most frequently in the available policies?
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT customer_phone FROM available_policies WHERE policy_type_code = (SELECT policy_type_code FROM available_policies GROUP BY policy_type_code ORDER BY count(*) DESC LIMIT 1)
What are all the customer phone numbers under the most popular policy type?
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT customer_phone FROM available_policies WHERE policy_type_code = (SELECT policy_type_code FROM available_policies GROUP BY policy_type_code ORDER BY count(*) DESC LIMIT 1)
Find the phone numbers of customers using the most common policy type among the available policies.
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT policy_type_code FROM available_policies GROUP BY policy_type_code HAVING count(*) > 4
Find the policy type used by more than 4 customers.
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT policy_type_code FROM available_policies GROUP BY policy_type_code HAVING count(*) > 4
Find the policy types more than 4 customers use. Show their type code.
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT sum(settlement_amount) , avg(settlement_amount) FROM settlements
Find the total and average amount of settlements.
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT sum(settlement_amount) , avg(settlement_amount) FROM settlements
Return the sum and average of all settlement amounts.
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT t2.service_name FROM first_notification_of_loss AS t1 JOIN services AS t2 ON t1.service_id = t2.service_id GROUP BY t1.service_id HAVING count(*) > 2
Find the name of services that have been used for more than 2 times in first notification of loss.
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT t2.service_name FROM first_notification_of_loss AS t1 JOIN services AS t2 ON t1.service_id = t2.service_id GROUP BY t1.service_id HAVING count(*) > 2
Which services have been used more than twice in first notification of loss? Return the service name.
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT t1.Effective_Date FROM claims AS t1 JOIN settlements AS t2 ON t1.claim_id = t2.claim_id GROUP BY t1.claim_id ORDER BY sum(t2.settlement_amount) DESC LIMIT 1
What is the effective date of the claim that has the largest amount of total settlement?
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT t1.Effective_Date FROM claims AS t1 JOIN settlements AS t2 ON t1.claim_id = t2.claim_id GROUP BY t1.claim_id ORDER BY sum(t2.settlement_amount) DESC LIMIT 1
Find the claim that has the largest total settlement amount. Return the effective date of the claim.
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT count(*) FROM customers AS t1 JOIN customers_policies AS t2 ON t1.customer_id = t2.customer_id WHERE t1.customer_name = "Dayana Robel"
How many policies are listed for the customer named "Dayana Robel"?
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT count(*) FROM customers AS t1 JOIN customers_policies AS t2 ON t1.customer_id = t2.customer_id WHERE t1.customer_name = "Dayana Robel"
Count the total number of policies used by the customer named "Dayana Robel".
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT t1.customer_name FROM customers AS t1 JOIN customers_policies AS t2 ON t1.customer_id = t2.customer_id GROUP BY t1.customer_name ORDER BY count(*) DESC LIMIT 1
What is the name of the customer who has the most policies listed?
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')
insurance_fnol
SELECT t1.customer_name FROM customers AS t1 JOIN customers_policies AS t2 ON t1.customer_id = t2.customer_id GROUP BY t1.customer_name ORDER BY count(*) DESC LIMIT 1
Which customer uses the most policies? Give me the customer name.
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_name VARCHAR(40), PRIMARY KEY (Customer_ID) ); CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_name VARCHAR(40), PRIMARY KEY (Service_ID) ); CREATE TABLE Available_Policies ( Policy_ID INTEGER NOT NULL, policy_type_code CHAR(15), Customer_Phone VARCHAR(255), PRIMARY KEY (Policy_ID), UNIQUE (Policy_ID) ); CREATE TABLE Customers_Policies ( Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Opened DATE, Date_Closed DATE, PRIMARY KEY (Customer_ID, Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID), FOREIGN KEY (Policy_ID) REFERENCES Available_Policies (Policy_ID) ); CREATE TABLE First_Notification_of_Loss ( FNOL_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, PRIMARY KEY (FNOL_ID), UNIQUE (FNOL_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID), FOREIGN KEY (Customer_ID, Policy_ID) REFERENCES Customers_Policies (Customer_ID,Policy_ID) ); CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, FNOL_ID INTEGER NOT NULL, Effective_Date DATE, PRIMARY KEY (Claim_ID), UNIQUE (Claim_ID), FOREIGN KEY (FNOL_ID) REFERENCES First_Notification_of_Loss (FNOL_ID) ); CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER, Effective_Date DATE, Settlement_Amount REAL, PRIMARY KEY (Settlement_ID), UNIQUE (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ); INSERT INTO `Customers` (`Customer_ID`, `Customer_name`) VALUES (194, 'America Jaskolski') INSERT INTO `Services` (`Service_ID`, `Service_name`) VALUES (1, 'New policy application') INSERT INTO `Available_Policies` (`Policy_ID`, `policy_type_code`, `Customer_Phone`) VALUES (246, 'Life Insurance', '+16(2) INSERT INTO `Customers_Policies` (`Customer_ID`, `Policy_ID`, `Date_Opened`, `Date_Closed`) VALUES (214, 257, '2016-11-19', '2018-03-04') INSERT INTO `First_Notification_of_Loss` (`FNOL_ID`, `Customer_ID`, `Policy_ID`, `Service_ID`) VALUES (532, 214, 257, 6) INSERT INTO `Claims` (`Claim_ID`, `FNOL_ID`, `Effective_Date`) VALUES (134, 1722, '1973-08-18') INSERT INTO `Settlements` (`Settlement_ID`, `Claim_ID`, `Effective_Date`, `Settlement_Amount`) VALUES (161, 717, '2009-11-20', '6451.65')