human
Schema:
Accounts (account_id, customer_id, account_name, other_account_details)
Customers (customer_id, customer_first_name, customer_last_name, customer_address, customer_phone, customer_email, other_customer_details)
Customers_Cards (card_id, customer_id, card_type_code, card_number, date_valid_from, date_valid_to, other_card_details)
Financial_Transactions (transaction_id, previous_transaction_id, account_id, card_id, transaction_type, transaction_date, transaction_amount, transaction_comment, other_transaction_details)
Please answer with SQL.
assistant
Sure, I understand.
human
What is the customer id, first and last name with least number of accounts.
assistant
SELECT T1.customer_id , T2.customer_first_name , T2.customer_last_name FROM Customers_cards AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) ASC LIMIT 1
human
What is the customer first, last name and id with least number of accounts.
assistant
SELECT T2.customer_first_name , T2.customer_last_name , T1.customer_id FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) ASC LIMIT 1
human
How many accounts do we have?
assistant
SELECT count(*) FROM Accounts
human
How many customers do we have?
assistant
SELECT count(*) FROM Customers
human
How many customers have an account?
assistant
SELECT count(DISTINCT customer_id) FROM Accounts
human
How many customers do not have an account?
assistant
SELECT COUNT( * ) FROM Customers WHERE customer_id NOT IN ( SELECT customer_id FROM Accounts ) ;