Krishna Prakash
Initial commit For SQL Practice Platform
e7cf806
[
{
"id": "q1",
"title": "List all customers",
"difficulty": "Beginner",
"description": "Retrieve the names and emails of all customers.",
"hint": "Use SELECT on the customers table.",
"expected_sql": "SELECT name, email FROM customers;"
},
{
"id": "q2",
"title": "Show savings accounts",
"difficulty": "Beginner",
"description": "List all accounts of type 'Savings' with their balances.",
"hint": "Use WHERE clause to filter by account_type.",
"expected_sql": "SELECT account_id, balance FROM accounts WHERE account_type = 'Savings';"
},
{
"id": "q3",
"title": "Find customers in New York",
"difficulty": "Beginner",
"description": "Show the names and ages of customers living in New York.",
"hint": "Use WHERE clause to filter by city.",
"expected_sql": "SELECT name, age FROM customers WHERE city = 'New York';"
},
{
"id": "q4",
"title": "Count total accounts",
"difficulty": "Beginner",
"description": "Count the total number of accounts in the system.",
"hint": "Use COUNT() function on the accounts table.",
"expected_sql": "SELECT COUNT(*) AS total_accounts FROM accounts;"
},
{
"id": "q5",
"title": "List accounts opened in 2023",
"difficulty": "Beginner",
"description": "Retrieve all accounts opened in 2023.",
"hint": "Use WHERE clause with LIKE on opened_on.",
"expected_sql": "SELECT account_id, account_type, opened_on FROM accounts WHERE opened_on LIKE '2023%';"
},
{
"id": "q6",
"title": "List distinct account types",
"difficulty": "Beginner",
"description": "Get all unique account types from the accounts table.",
"hint": "Use DISTINCT to avoid duplicate account types.",
"expected_sql": "SELECT DISTINCT account_type FROM accounts;"
},
{
"id": "q7",
"title": "Find accounts for John Doe",
"difficulty": "Beginner",
"description": "List all accounts owned by John Doe.",
"hint": "Join accounts with customers and filter by name.",
"expected_sql": "SELECT a.account_id, a.account_type, a.balance FROM accounts a JOIN customers c ON a.customer_id = c.customer_id WHERE c.name = 'John Doe';"
},
{
"id": "q8",
"title": "Show customers under 30",
"difficulty": "Beginner",
"description": "Retrieve the names and cities of customers younger than 30 years old.",
"hint": "Use WHERE clause to filter by age.",
"expected_sql": "SELECT name, city FROM customers WHERE age < 30;"
},
{
"id": "q9",
"title": "List loan accounts",
"difficulty": "Beginner",
"description": "Show all accounts of type 'Loan' with their balances.",
"hint": "Use WHERE clause to filter by account_type.",
"expected_sql": "SELECT account_id, balance FROM accounts WHERE account_type = 'Loan';"
},
{
"id": "q10",
"title": "Find customer emails",
"difficulty": "Beginner",
"description": "Retrieve the names and email addresses of all customers.",
"hint": "Select name and email from customers table.",
"expected_sql": "SELECT name, email FROM customers;"
},
{
"id": "q11",
"title": "Count accounts per customer",
"difficulty": "Intermediate",
"description": "Show the number of accounts each customer owns.",
"hint": "Join customers and accounts, then GROUP BY customer name.",
"expected_sql": "SELECT c.name, COUNT(a.account_id) AS account_count FROM customers c LEFT JOIN accounts a ON c.customer_id = a.customer_id GROUP BY c.name;"
},
{
"id": "q12",
"title": "Total balance per customer",
"difficulty": "Intermediate",
"description": "Calculate the total balance across all accounts for each customer.",
"hint": "Join customers and accounts, then GROUP BY customer name and SUM balance.",
"expected_sql": "SELECT c.name, SUM(a.balance) AS total_balance FROM customers c JOIN accounts a ON c.customer_id = a.customer_id GROUP BY c.name;"
},
{
"id": "q13",
"title": "Average balance by account type",
"difficulty": "Intermediate",
"description": "Find the average balance for each account type.",
"hint": "GROUP BY account_type and use AVG on balance.",
"expected_sql": "SELECT account_type, AVG(balance) AS avg_balance FROM accounts GROUP BY account_type;"
},
{
"id": "q14",
"title": "Customers with multiple accounts",
"difficulty": "Intermediate",
"description": "List customers who have more than one account.",
"hint": "Join customers and accounts, GROUP BY customer, and use HAVING clause.",
"expected_sql": "SELECT c.name, COUNT(a.account_id) AS account_count FROM customers c JOIN accounts a ON c.customer_id = a.customer_id GROUP BY c.name HAVING COUNT(a.account_id) > 1;"
},
{
"id": "q15",
"title": "Accounts with negative balance",
"difficulty": "Intermediate",
"description": "Show all accounts with a negative balance, including customer names.",
"hint": "Join accounts with customers and filter by balance < 0.",
"expected_sql": "SELECT a.account_id, c.name, a.account_type, a.balance FROM accounts a JOIN customers c ON a.customer_id = c.customer_id WHERE a.balance < 0;"
},
{
"id": "q16",
"title": "Customers with no accounts",
"difficulty": "Intermediate",
"description": "List customers who do not have any accounts.",
"hint": "Use LEFT JOIN and check for NULL in accounts table.",
"expected_sql": "SELECT c.name FROM customers c LEFT JOIN accounts a ON c.customer_id = a.customer_id WHERE a.account_id IS NULL;"
},
{
"id": "q17",
"title": "Account details with customer info",
"difficulty": "Intermediate",
"description": "Show account details including customer name and city.",
"hint": "Join accounts and customers tables.",
"expected_sql": "SELECT a.account_id, a.account_type, a.balance, c.name, c.city FROM accounts a JOIN customers c ON a.customer_id = c.customer_id;"
},
{
"id": "q18",
"title": "Count accounts by city",
"difficulty": "Intermediate",
"description": "Count the number of accounts for customers in each city.",
"hint": "Join customers and accounts, GROUP BY city.",
"expected_sql": "SELECT c.city, COUNT(a.account_id) AS account_count FROM customers c JOIN accounts a ON c.customer_id = a.customer_id GROUP BY c.city;"
},
{
"id": "q19",
"title": "Accounts opened before 2023",
"difficulty": "Intermediate",
"description": "List all accounts opened before 2023, including customer names.",
"hint": "Join accounts with customers and filter by opened_on.",
"expected_sql": "SELECT a.account_id, a.account_type, c.name FROM accounts a JOIN customers c ON a.customer_id = c.customer_id WHERE a.opened_on < '2023-01-01';"
},
{
"id": "q20",
"title": "Total balance by account type",
"difficulty": "Intermediate",
"description": "Calculate the total balance for each account type.",
"hint": "GROUP BY account_type and SUM balance.",
"expected_sql": "SELECT account_type, SUM(balance) AS total_balance FROM accounts GROUP BY account_type;"
},
{
"id": "q21",
"title": "Customers with highest total balance",
"difficulty": "Advanced",
"description": "Find the customer with the highest total balance across all their accounts.",
"hint": "Join tables, SUM balance, GROUP BY customer, and use LIMIT.",
"expected_sql": "SELECT c.name, SUM(a.balance) AS total_balance FROM customers c JOIN accounts a ON c.customer_id = a.customer_id GROUP BY c.name ORDER BY total_balance DESC LIMIT 1;"
},
{
"id": "q22",
"title": "Youngest customer with loan account",
"difficulty": "Advanced",
"description": "Identify the youngest customer who has a Loan account.",
"hint": "Join tables, filter by account_type, and use MIN on age.",
"expected_sql": "SELECT c.name, c.age FROM customers c JOIN accounts a ON c.customer_id = a.customer_id WHERE a.account_type = 'Loan' ORDER BY c.age ASC LIMIT 1;"
},
{
"id": "q23",
"title": "Account age in years",
"difficulty": "Advanced",
"description": "Calculate the age of each account in years as of '2025-07-11'.",
"hint": "Use JULIANDAY to calculate date difference and divide by 365.25.",
"expected_sql": "SELECT account_id, account_type, ROUND((JULIANDAY('2025-07-11') - JULIANDAY(opened_on)) / 365.25, 1) AS account_age FROM accounts;"
},
{
"id": "q24",
"title": "Customers with diverse account types",
"difficulty": "Advanced",
"description": "List customers who have more than one type of account.",
"hint": "Join tables, count distinct account types, and use HAVING.",
"expected_sql": "SELECT c.name, COUNT(DISTINCT a.account_type) AS type_count FROM customers c JOIN accounts a ON c.customer_id = a.customer_id GROUP BY c.name HAVING type_count > 1;"
},
{
"id": "q25",
"title": "Account openings by year",
"difficulty": "Advanced",
"description": "Show the number of accounts opened each year.",
"hint": "Use STRFTIME to extract year and GROUP BY.",
"expected_sql": "SELECT STRFTIME('%Y', opened_on) AS year, COUNT(account_id) AS account_count FROM accounts GROUP BY year;"
},
{
"id": "q26",
"title": "Customers with high negative balance",
"difficulty": "Advanced",
"description": "Find customers with a total balance less than -5000 across all accounts.",
"hint": "Join tables, SUM balance, and use HAVING clause.",
"expected_sql": "SELECT c.name, SUM(a.balance) AS total_balance FROM customers c JOIN accounts a ON c.customer_id = a.customer_id GROUP BY c.name HAVING total_balance < -5000;"
},
{
"id": "q27",
"title": "Oldest account per customer",
"difficulty": "Advanced",
"description": "Show the earliest opened account for each customer.",
"hint": "Join tables, use MIN on opened_on, and GROUP BY customer.",
"expected_sql": "SELECT c.name, MIN(a.opened_on) AS earliest_opened FROM customers c JOIN accounts a ON c.customer_id = a.customer_id GROUP BY c.name;"
},
{
"id": "q28",
"title": "Cities with high average balance",
"difficulty": "Advanced",
"description": "List cities where the average account balance is greater than 1000.",
"hint": "Join tables, GROUP BY city, and use HAVING clause.",
"expected_sql": "SELECT c.city, AVG(a.balance) AS avg_balance FROM customers c JOIN accounts a ON c.customer_id = a.customer_id GROUP BY c.city HAVING avg_balance > 1000;"
},
{
"id": "q29",
"title": "Customers with no savings accounts",
"difficulty": "Advanced",
"description": "List customers who do not have a Savings account.",
"hint": "Use NOT IN or LEFT JOIN to exclude customers with Savings accounts.",
"expected_sql": "SELECT c.name FROM customers c WHERE c.customer_id NOT IN (SELECT a.customer_id FROM accounts a WHERE a.account_type = 'Savings');"
},
{
"id": "q30",
"title": "Most common account type per city",
"difficulty": "Advanced",
"description": "Find the most common account type in each city.",
"hint": "Join tables, group by city and account_type, use subquery or LIMIT.",
"expected_sql": "SELECT c.city, a.account_type, COUNT(a.account_id) AS account_count FROM customers c JOIN accounts a ON c.customer_id = a.customer_id GROUP BY c.city, a.account_type HAVING COUNT(a.account_id) = (SELECT MAX(account_count) FROM (SELECT COUNT(account_id) AS account_count FROM accounts a2 JOIN customers c2 ON a2.customer_id = c2.customer_id WHERE c2.city = c.city GROUP BY a2.account_type) AS counts);"
}
]