SQL-Challenge-4
SQL-Challenge-4
Solutions by Thanaselvi C
on 26 Dec 2023
@Thanaselvi
1. What are the names of all the customers who live in New York?
@Thanaselvi
2. What is the total number of accounts in the Accounts table?
Syntax: Output:
total_count
15
select count(accountid) as total_count
from accounts;
@Thanaselvi
3. What is the total balance of all checking accounts?
Syntax: Output:
Total_Balance
31000.00
select sum(balance) as Total_Balance
from Accounts
where accounttype = 'checking';
@Thanaselvi
4. What is the total balance of all accounts associated with customers who live in
Los Angeles?
Syntax: Output:
Total_Balance
75000.00
select sum(a.balance) as Total_Balance
from Accounts as A inner join Customers as C
on a.CustomerID=c.CustomerID
where city='Los Angeles';
@Thanaselvi
5. Which branch has the highest average account balance?
Syntax Output:
@Thanaselvi
6. Which customer has the highest current balance in their accounts?
Syntax Output:
select top 1 c.firstname,c.lastname, max(a.balance) firstna lastnam Maxbala
as Maxbalance me e nce
from customers as c join accounts as a
on c.customerid = a.customerid 50000.
Michael Lee
group by c.firstname,c.lastname 00
order by Maxbalance
desc;
@Thanaselvi
7. Which customer has made the most transactions in the Transactions table?
Syntax Output:
select top 1 c.firstname,c.lastname, count(t.transactionid)
as Total_Transactions lastnam Total_Transac
from customers as c join accounts as a firstname
e tions
on c.CustomerID= a.CustomerID
join Transactions AS t
Jane Doe 4
on a.AccountID = t.AccountID
group by c.firstname,c.lastname
order by Total_Transactions desc;
@Thanaselvi
8.Which branch has the highest total balance across all of its accounts?
Syntax Output:
@Thanaselvi
9. Which customer has the highest total balance across all of their accounts,
including savings and checking accounts?
Syntax Output:
Syntax Output: