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
Show id, first and last names for all customers with at least two cards.
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 HAVING count(*) >= 2
human
Show all card type codes and the number of customers holding cards in each type.
assistant
SELECT card_type_code , count(DISTINCT customer_id) FROM Customers_cards GROUP BY card_type_code
human
Show the number of customer cards.
assistant
SELECT count(*) FROM Customers_cards
human
Show all customer ids and the number of cards owned by each customer.
assistant
SELECT customer_id , count(*) FROM Customers_cards GROUP BY customer_id
human
What is the customer id with most number of cards, and how many does he have?
assistant
SELECT customer_id , count(*) FROM Customers_cards GROUP BY customer_id ORDER BY count(*) DESC LIMIT 1
human
What are card ids, customer ids, card types, and card numbers for each customer card?
assistant
SELECT card_id , customer_id , card_type_code , card_number FROM Customers_cards ;