Database Based On Finance Sector SQL
Database Based On Finance Sector SQL
E FINANCIAL
MANAGEMENT
DATABASE
By Group 2
DATABASE TABLES FOR
FINANCE SECTOR
2. Client Table
1. Employee Table
3. Account Table
4. Transaction Table
DATABASE DIAGRAM
Relationships:
• Clients to Accounts (One-to-Many):
One Client can have many Accounts.
UPDATE Query:
UPDATE Clients
SET email = '[email protected]’,
phone_number = '123-456-7890'
WHERE first_name = 'Michael' AND
last_name = 'Jordan';
DELETE Query:
DELETE FROM Transactions
WHERE transaction_id = 14;
QUERIES
ALTER Query:
SELECT DISTINCT
transaction_type
FROM Transactions;
AGGREGATE FUNCTIONS
1. MIN() (Minimum) 2. MAX() (Maximum) 3. AVG()
(Average)
Scenario: Find the
Scenario: Find Scenario: Find average balance of
the minimum the maximum all accounts.
balance across all balance across all
accounts. accounts.
Scenario: Calculate the total amount of money Scenario: Count how many clients each employee
SELECT employee_id,
SELECT SUM(amount) AS
COUNT(client_id) AS client_count
total_deposits
FROM Clients
FROM Transactions
GROUP BY employee_id;
WHERE transaction_type =
'Deposit';
AGGREGATE FUNCTIONS
Combination Example:
Scenario: Show the minimum, maximum, average balances and standard deviation of balances per
account type (Savings vs Checking)
SELECT account_type,
MIN(balance) AS min_balance,
MAX(balance) AS max_balance,
AVG(balance) AS avg_balance,
STDEV(balance) AS
balance_stdev
FROM Accounts
GROUP BY account_type;
JOINS
1. Inner Join:
Scenario: Retrieve the list of clients and their associated accounts where both
clients and accounts exist.
SELECT Clients.first_name,
Clients.last_name,
Accounts.account_type,
Accounts.balance
FROM Clients
INNER JOIN Accounts
ON Clients.client_id =
Accounts.client_id;
JOINS
2. Left Join:
Scenario: Retrieve all clients, whether they have an account or not, along with their
account details if available. Left Join include all clients, even if they don't have
accounts.
SELECT Clients.first_name,
Clients.last_name,
Accounts.account_type,
Accounts.balance
FROM Clients
LEFT JOIN Accounts
ON Clients.client_id =
Accounts.client_id;
JOINS
3. Anti-Left Join:
Scenario: Retrieve only the records from the Client table that do not have matching
records in the Accounts table
SELECT Clients.first_name,
Clients.last_name,
Accounts.account_type,
Accounts.balance
FROM Clients
RIGHT JOIN Accounts
ON Clients.client_id =
Accounts.client_id;
JOINS
5. Anti-Right Join:
Scenario: Retrieve only the records from the Accounts table that do not have
matching
records in the Clients table
SELECT Clients.first_name,
Clients.last_name,
Accounts.account_type,
Accounts.balance
FROM Clients
FULL OUTER JOIN Accounts
ON Clients.client_id =
Accounts.client_id;
JOINS
7. Cross Join:
Scenario: Create all possible combinations of clients and
accounts
SELECT Clients.first_name,
Clients.last_name, Clients.email,
Accounts.account_type
FROM Clients
CROSS JOIN Accounts;
THANK YOU!