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

Database Based On Finance Sector SQL

Uploaded by

tsawant1803
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Database Based On Finance Sector SQL

Uploaded by

tsawant1803
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

COMPREHENSIV

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.

• Employees to Clients (One-to-Many):


One Employee manages many
Clients.

• Accounts to Transactions (One-to-


Many):
One Account can have many
Transactions.
QUERIES
Insert Query:
INSERT INTO Clients (first_name, last_name,
email, phone_number, addresses,
employee_id)
VALUES ('Michael', 'Jordan',
'[email protected]', '999-999-9999',
'123 Jump St', 1);

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:

ALTER TABLE Clients


ADD DOB Date;

ALTER TABLE Clients


DROP COLUMN DOB;
QUERIES
LIKE: Searching for Patterns in Data
SELECT *
FROM Clients
WHERE last_name LIKE
'%son';

DISTINCT: Eliminating Duplicates


from Results

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.

SELECT MIN(balance) AS SELECT MAX(balance) AS SELECT AVG(balance)


min_balance max_balance AS avg_balance
FROM Accounts; FROM Accounts; FROM Accounts;
AGGREGATE FUNCTIONS
4. SUM() (Total) 5. COUNT() (Number of Entries)

Scenario: Calculate the total amount of money Scenario: Count how many clients each employee

deposited into all accounts. is managing.

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
LEFT JOIN Accounts ON Clients.client_id =
Accounts.client_id
WHERE Accounts.client_id IS NULL;
JOINS
4. Right Join:
Scenario: Retrieve a list of all accounts and their respective clients, showing even accounts without associated client data.
It highlights accounts that are not linked to any client.

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
RIGHT JOIN Accounts ON Clients.client_id =
Accounts.client_id
WHERE Clients.client_id IS NULL;
JOINS
6. Full Outer Join:
Scenario: Get a combined list of all clients and accounts, including those with no relationship.
It will show clients without accounts and accounts without clients.

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!

You might also like