spider_version
int64
1
2
db_id
stringclasses
204 values
schema
stringclasses
187 values
question
stringlengths
3
328
query
stringlengths
20
3.81k
1
customers_card_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` ) )
Show the customer ids and firstname without a credit card.
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"
1
customers_card_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` ) )
What are the ids and first names of customers who do not hold a credit card?
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"
1
customers_card_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` ) )
Show all card type codes.
SELECT DISTINCT card_type_code FROM Customers_Cards
1
customers_card_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` ) )
What are the different card type codes?
SELECT DISTINCT card_type_code FROM Customers_Cards
1
customers_card_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` ) )
Show the number of card types.
SELECT count(DISTINCT card_type_code) FROM Customers_Cards
1
customers_card_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` ) )
How many different card types are there?
SELECT count(DISTINCT card_type_code) FROM Customers_Cards
1
customers_card_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` ) )
Show all transaction types.
SELECT DISTINCT transaction_type FROM Financial_Transactions
1
customers_card_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` ) )
What are the different types of transactions?
SELECT DISTINCT transaction_type FROM Financial_Transactions
1
customers_card_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` ) )
Show the number of transaction types.
SELECT count(DISTINCT transaction_type) FROM Financial_Transactions
1
customers_card_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` ) )
How many different types of transactions are there?
SELECT count(DISTINCT transaction_type) FROM Financial_Transactions
1
customers_card_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` ) )
What is the average and total transaction amount?
SELECT avg(transaction_amount) , sum(transaction_amount) FROM Financial_transactions
1
customers_card_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` ) )
Return the average transaction amount, as well as the total amount of all transactions.
SELECT avg(transaction_amount) , sum(transaction_amount) FROM Financial_transactions
1
customers_card_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` ) )
Show the card type codes and the number of 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
1
customers_card_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` ) )
What are the different card types, and how many transactions have been made with each?
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
1
customers_card_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` ) )
Show the transaction type and the number of transactions.
SELECT transaction_type , count(*) FROM Financial_transactions GROUP BY transaction_type
1
customers_card_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` ) )
What are the different transaction types, and how many transactions of each have taken place?
SELECT transaction_type , count(*) FROM Financial_transactions GROUP BY transaction_type
1
customers_card_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` ) )
What is the transaction type that has processed the greatest total amount in transactions?
SELECT transaction_type FROM Financial_transactions GROUP BY transaction_type ORDER BY sum(transaction_amount) DESC LIMIT 1
1
customers_card_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` ) )
Return the type of transaction with the highest total amount.
SELECT transaction_type FROM Financial_transactions GROUP BY transaction_type ORDER BY sum(transaction_amount) DESC LIMIT 1
1
customers_card_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` ) )
Show the account id and the number of transactions for each account
SELECT account_id , count(*) FROM Financial_transactions GROUP BY account_id
1
customers_card_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` ) )
What are the different account ids that have made financial transactions, as well as how many transactions correspond to each?
SELECT account_id , count(*) FROM Financial_transactions GROUP BY account_id
1
race_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") )
How many tracks do we have?
SELECT count(*) FROM track
1
race_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") )
Count the number of tracks.
SELECT count(*) FROM track
1
race_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") )
Show the name and location for all tracks.
SELECT name , LOCATION FROM track
1
race_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") )
What are the names and locations of all tracks?
SELECT name , LOCATION FROM track
1
race_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") )
Show names and seatings, ordered by seating for all tracks opened after 2000.
SELECT name , seating FROM track WHERE year_opened > 2000 ORDER BY seating
1
race_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") )
What are the names and seatings for all tracks opened after 2000, ordered by seating?
SELECT name , seating FROM track WHERE year_opened > 2000 ORDER BY seating
1
race_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") )
What is the name, location and seating for the most recently opened track?
SELECT name , LOCATION , seating FROM track ORDER BY year_opened DESC LIMIT 1
1
race_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") )
Return the name, location, and seating of the track that was opened in the most recent year.
SELECT name , LOCATION , seating FROM track ORDER BY year_opened DESC LIMIT 1
1
race_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") )
What is the minimum, maximum, and average seating for all tracks.
SELECT min(seating) , max(seating) , avg(seating) FROM track
1
race_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") )
Return the minimum, maximum, and average seating across all tracks.
SELECT min(seating) , max(seating) , avg(seating) FROM track
1
race_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") )
Show the name, location, open year for all tracks with a seating higher than the average.
SELECT name , LOCATION , year_opened FROM track WHERE seating > (SELECT avg(seating) FROM track)
1
race_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") )
What are the names, locations, and years of opening for tracks with seating higher than average?
SELECT name , LOCATION , year_opened FROM track WHERE seating > (SELECT avg(seating) FROM track)
1
race_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") )
What are distinct locations where tracks are located?
SELECT DISTINCT LOCATION FROM track
1
race_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") )
Give the different locations of tracks.
SELECT DISTINCT LOCATION FROM track
1
race_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") )
How many races are there?
SELECT count(*) FROM race
1
race_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") )
Count the number of races.
SELECT count(*) FROM race
1
race_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") )
What are the distinct classes that races can have?
SELECT DISTINCT CLASS FROM race
1
race_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") )
Return the different classes of races.
SELECT DISTINCT CLASS FROM race
1
race_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") )
Show name, class, and date for all races.
SELECT name , CLASS , date FROM race
1
race_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") )
What are the names, classes, and dates for all races?
SELECT name , CLASS , date FROM race
1
race_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") )
Show the race class and number of races in each class.
SELECT CLASS , count(*) FROM race GROUP BY CLASS
1
race_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") )
What are the different classes of races, and how many races correspond to each?
SELECT CLASS , count(*) FROM race GROUP BY CLASS
1
race_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") )
What is the race class with most number of races.
SELECT CLASS FROM race GROUP BY CLASS ORDER BY count(*) DESC LIMIT 1
1
race_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") )
Give the class of races that is most common.
SELECT CLASS FROM race GROUP BY CLASS ORDER BY count(*) DESC LIMIT 1
1
race_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") )
List the race class with at least two races.
SELECT CLASS FROM race GROUP BY CLASS HAVING count(*) >= 2
1
race_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") )
What are the classes of races that have two or more corresponding races?
SELECT CLASS FROM race GROUP BY CLASS HAVING count(*) >= 2
1
race_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") )
What are the names for tracks without a race in class 'GT'.
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'
1
race_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") )
Give the names of tracks that do not have a race in the class 'GT'.
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'
1
race_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") )
Show all track names that have had no races.
SELECT name FROM track WHERE track_id NOT IN (SELECT track_id FROM race)
1
race_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") )
Return the names of tracks that have no had any races.
SELECT name FROM track WHERE track_id NOT IN (SELECT track_id FROM race)
1
race_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") )
Show year where a track with a seating at least 5000 opened and a track with seating no more than 4000 opened.
SELECT year_opened FROM track WHERE seating BETWEEN 4000 AND 5000
1
race_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") )
What are the years of opening for tracks with seating between 4000 and 5000?
SELECT year_opened FROM track WHERE seating BETWEEN 4000 AND 5000
1
race_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") )
Show the name of track and the number of races in each 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
1
race_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") )
What are the names of different tracks, and how many races has each had?
SELECT T2.name , count(*) FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id GROUP BY T1.track_id
1
race_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") )
Show the name of track with most number of races.
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
1
race_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") )
What is the name of the track that has had the greatest number of races?
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
1
race_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") )
Show the name and date for each race and its track name.
SELECT T1.name , T1.date , T2.name FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id
1
race_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") )
What are the names and dates of races, and the names of the tracks where they are held?
SELECT T1.name , T1.date , T2.name FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id
1
race_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") )
Show the name and location of track with 1 race.
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
1
race_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") )
What are the names and locations of tracks that have had exactly 1 race?
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
1
race_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") )
Find the locations where have both tracks with more than 90000 seats and tracks with less than 70000 seats.
SELECT LOCATION FROM track WHERE seating > 90000 INTERSECT SELECT LOCATION FROM track WHERE seating < 70000
1
race_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") )
What are the locations that have both tracks with more than 90000 seats, and tracks with fewer than 70000 seats?
SELECT LOCATION FROM track WHERE seating > 90000 INTERSECT SELECT LOCATION FROM track WHERE seating < 70000
1
coffee_shop
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") )
How many members have the black membership card?
SELECT count(*) FROM member WHERE Membership_card = 'Black'
1
coffee_shop
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") )
Find the number of members living in each address.
SELECT count(*) , address FROM member GROUP BY address
1
coffee_shop
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") )
Give me the names of members whose address is in Harford or Waterbury.
SELECT name FROM member WHERE address = 'Harford' OR address = 'Waterbury'
1
coffee_shop
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") )
Find the ids and names of members who are under age 30 or with black membership card.
SELECT name , member_id FROM member WHERE Membership_card = 'Black' OR age < 30
1
coffee_shop
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") )
Find the purchase time, age and address of each member, and show the results in the order of purchase time.
SELECT Time_of_purchase , age , address FROM member ORDER BY Time_of_purchase
1
coffee_shop
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") )
Which membership card has more than 5 members?
SELECT Membership_card FROM member GROUP BY Membership_card HAVING count(*) > 5
1
coffee_shop
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") )
Which address has both members younger than 30 and members older than 40?
SELECT address FROM member WHERE age < 30 INTERSECT SELECT address FROM member WHERE age > 40
1
coffee_shop
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") )
What is the membership card held by both members living in Hartford and ones living in Waterbury address?
SELECT membership_card FROM member WHERE address = 'Hartford' INTERSECT SELECT membership_card FROM member WHERE address = 'Waterbury'
1
coffee_shop
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") )
How many members are not living in Hartford?
SELECT count(*) FROM member WHERE address != 'Hartford'
1
coffee_shop
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") )
Which address do not have any member with the black membership card?
SELECT address FROM member EXCEPT SELECT address FROM member WHERE Membership_card = 'Black'
1
coffee_shop
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") )
Show the shop addresses ordered by their opening year.
SELECT address FROM shop ORDER BY open_year
1
coffee_shop
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") )
What are the average score and average staff number of all shops?
SELECT avg(num_of_staff) , avg(score) FROM shop
1
coffee_shop
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") )
Find the id and address of the shops whose score is below the average score.
SELECT shop_id , address FROM shop WHERE score < (SELECT avg(score) FROM shop)
1
coffee_shop
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") )
Find the address and staff number of the shops that do not have any happy hour.
SELECT address , num_of_staff FROM shop WHERE shop_id NOT IN (SELECT shop_id FROM happy_hour)
1
coffee_shop
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") )
What are the id and address of the shops which have a happy hour in May?
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'
1
coffee_shop
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") )
which shop has happy hour most frequently? List its id and number of happy hours.
SELECT shop_id , count(*) FROM happy_hour GROUP BY shop_id ORDER BY count(*) DESC LIMIT 1
1
coffee_shop
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") )
Which month has the most happy hours?
SELECT MONTH FROM happy_hour GROUP BY MONTH ORDER BY count(*) DESC LIMIT 1
1
coffee_shop
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") )
Which months have more than 2 happy hours?
SELECT MONTH FROM happy_hour GROUP BY MONTH HAVING count(*) > 2
1
insurance_fnol
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) )
Find all the phone numbers.
SELECT customer_phone FROM available_policies
1
insurance_fnol
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) )
What are all the phone numbers?
SELECT customer_phone FROM available_policies
1
insurance_fnol
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) )
What are the customer phone numbers under the policy "Life Insurance"?
SELECT customer_phone FROM available_policies WHERE policy_type_code = "Life Insurance"
1
insurance_fnol
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) )
What are the phone numbers of customers using the policy with the code "Life Insurance"?
SELECT customer_phone FROM available_policies WHERE policy_type_code = "Life Insurance"
1
insurance_fnol
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) )
Which policy type has the most records in the database?
SELECT policy_type_code FROM available_policies GROUP BY policy_type_code ORDER BY count(*) DESC LIMIT 1
1
insurance_fnol
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) )
Which policy type appears most frequently in the available policies?
SELECT policy_type_code FROM available_policies GROUP BY policy_type_code ORDER BY count(*) DESC LIMIT 1
1
insurance_fnol
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) )
What are all the customer phone numbers under the most popular policy type?
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)
1
insurance_fnol
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) )
Find the phone numbers of customers using the most common policy type among the available policies.
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)
1
insurance_fnol
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) )
Find the policy type used by more than 4 customers.
SELECT policy_type_code FROM available_policies GROUP BY policy_type_code HAVING count(*) > 4
1
insurance_fnol
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) )
Find the policy types more than 4 customers use. Show their type code.
SELECT policy_type_code FROM available_policies GROUP BY policy_type_code HAVING count(*) > 4
1
insurance_fnol
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) )
Find the total and average amount of settlements.
SELECT sum(settlement_amount) , avg(settlement_amount) FROM settlements
1
insurance_fnol
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) )
Return the sum and average of all settlement amounts.
SELECT sum(settlement_amount) , avg(settlement_amount) FROM settlements
1
insurance_fnol
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) )
Find the name of services that have been used for more than 2 times in first notification of loss.
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
1
insurance_fnol
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) )
Which services have been used more than twice in first notification of loss? Return the service name.
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
1
insurance_fnol
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) )
What is the effective date of the claim that has the largest amount of total settlement?
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
1
insurance_fnol
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) )
Find the claim that has the largest total settlement amount. Return the effective date of the claim.
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
1
insurance_fnol
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) )
How many policies are listed for the customer named "Dayana Robel"?
SELECT count(*) FROM customers AS t1 JOIN customers_policies AS t2 ON t1.customer_id = t2.customer_id WHERE t1.customer_name = "Dayana Robel"
1
insurance_fnol
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) )
Count the total number of policies used by the customer named "Dayana Robel".
SELECT count(*) FROM customers AS t1 JOIN customers_policies AS t2 ON t1.customer_id = t2.customer_id WHERE t1.customer_name = "Dayana Robel"
1
insurance_fnol
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) )
What is the name of the customer who has the most policies listed?
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
1
insurance_fnol
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) )
Which customer uses the most policies? Give me the customer name.
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