0% found this document useful (0 votes)
20 views

SQL-Challenge-4

The document outlines SQL challenges hosted on Steeldata.org, with solutions provided by Thanaselvi C on December 26, 2023. It includes various SQL queries to retrieve customer names, account totals, balances, and transaction counts for different conditions. Each challenge is accompanied by the corresponding SQL syntax and expected output.

Uploaded by

vijaybagul333
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

SQL-Challenge-4

The document outlines SQL challenges hosted on Steeldata.org, with solutions provided by Thanaselvi C on December 26, 2023. It includes various SQL queries to retrieve customer names, account totals, balances, and transaction counts for different conditions. Each challenge is accompanied by the corresponding SQL syntax and expected output.

Uploaded by

vijaybagul333
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

SQL Challenge-4

Challenge hosted on Steeldata.org

Solutions by Thanaselvi C

on 26 Dec 2023

@Thanaselvi
1. What are the names of all the customers who live in New York?

Syntax: Output: customer_name


John Doe
select concat_ws(' ',firstname,lastname) Jane Doe
as customer_name
from customers
where city= '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:

select top 1 b.branchname , branchnam


AvgBalance
round(avg(a.balance),2) as AvgBalance e
from branches as b join accounts as a
on b.branchid= a.BranchID North 30000.000
group by b.branchname Beach 000
order by avgbalance desc;

@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:

select top 1 b.branchname, sum(a.balance) branchname Total_balance


as Total_balance
from accounts as a join branches as b
North Beach 60000.00
on a.branchid=b.branchid
group by branchname
order by Total_balance desc;

@Thanaselvi
9. Which customer has the highest total balance across all of their accounts,
including savings and checking accounts?

Syntax Output:

select TOP 1 c.firstname,c.lastname,sum(a.balance) firstna lastnam High_ba


as High_balance me e lance
from customers as c join accounts as a
50000.
on c.CustomerID=A.CustomerID Michael Lee
00
WHERE ACCOUNTTYPE = 'SAVINGS'
GROUP BY firstname,lastname
ORDER BY High_balance DESC;
@Thanaselvi
10. Which branch has the highest number of transactions in the Transactions
table?

Syntax Output:

SELECT top 1 B.BRANCHNAME, COUNT(T.TRANSACTIONID)


AS high_trans
from branches as b join ACCOUNTS AS A BRANCHNAME high_trans
on B.BranchID=A.BranchID
join Transactions AS T
on A.AccountID=T.ACCOUNTID Main 4
group by branchname
order by high_trans desc; @Thanaselvi

You might also like