filmov
tv
SQL Tutorial - Join 3 tables with WHERE clause | SQL Interview Questions

Показать описание
CREATE TABLE Customers (
customer_id INT PRIMARY KEY,
customer_name VARCHAR(50),
email VARCHAR(50),
address VARCHAR(100),
phone_number VARCHAR(15)
);
CREATE TABLE Accounts (
account_id INT PRIMARY KEY,
customer_id INT,
account_number VARCHAR(20),
account_type VARCHAR(50),
balance DECIMAL(10, 2),
FOREIGN KEY (customer_id) REFERENCES Customers(customer_id)
);
CREATE TABLE Deposits (
deposit_id INT PRIMARY KEY,
account_id INT,
deposit_date DATE,
deposit_amount DECIMAL(10, 2),
FOREIGN KEY (account_id) REFERENCES Accounts(account_id)
);
INSERT INTO Customers (customer_id, customer_name, email, address, phone_number)
VALUES
INSERT INTO Accounts (account_id, customer_id, account_number, account_type, balance)
VALUES
(1, 1, '123456789', 'Savings', 1000.00),
(2, 2, '987654321', 'Checking', 500.00),
(3, 3, '654321098', 'Savings', 2500.00),
(4, 4, '789012345', 'Checking', 1500.00),
(5, 5, '543210987', 'Savings', 2000.00),
(6, 6, '901234567', 'Checking', 3000.00),
(7, 7, '234567890', 'Savings', 1800.00),
(8, 8, '876543210', 'Checking', 1200.00),
(9, 9, '567890123', 'Savings', 3500.00),
(10, 10, '432109876', 'Checking', 800.00),
(11, 11, '345678901', 'Savings', 4000.00),
(12, 12, '678901234', 'Checking', 2200.00),
(13, 13, '456789012', 'Savings', 1500.00),
(14, 14, '789012345', 'Checking', 3000.00),
(15, 15, '543210987', 'Savings', 2800.00);
INSERT INTO Deposits (deposit_id, account_id, deposit_date, deposit_amount)
VALUES
(1, 1, '2023-01-01', 500.00),
(2, 2, '2023-01-05', 1000.00),
(3, 3, '2023-01-10', 1500.00),
(4, 4, '2023-01-15', 2000.00),
(5, 5, '2023-01-20', 2500.00);
INSERT INTO Deposits (deposit_id, account_id, deposit_date, deposit_amount)
VALUES
(6, 2, '2023-07-10', 1200.00),
(7, 3, '2023-07-15', 1500.00),
(8, 3, '2023-07-17', 1800.00),
(9, 3, '2023-07-20', 2000.00),
(10, 4, '2023-07-25', 1600.00),
(11, 4, '2023-07-28', 1400.00),
(12, 4, '2023-07-30', 2000.00),
(13, 5, '2023-07-01', 1000.00),
(14, 5, '2023-07-05', 800.00),
(15, 5, '2023-07-08', 1200.00);
INSERT INTO Deposits (deposit_id, account_id, deposit_date, deposit_amount)
VALUES
(16, 1, '2023-06-01', 800.00),
(17, 1, '2023-06-03', 900.00),
(18, 2, '2023-06-05', 1000.00),
(19, 2, '2023-06-10', 1200.00),
(20, 3, '2023-06-15', 1500.00),
(21, 3, '2023-06-18', 1800.00),
(22, 4, '2023-06-20', 1600.00),
(23, 4, '2023-06-25', 1400.00),
(24, 5, '2023-06-30', 2000.00);
Subscribe Now and Stay Updated! 🔔
customer_id INT PRIMARY KEY,
customer_name VARCHAR(50),
email VARCHAR(50),
address VARCHAR(100),
phone_number VARCHAR(15)
);
CREATE TABLE Accounts (
account_id INT PRIMARY KEY,
customer_id INT,
account_number VARCHAR(20),
account_type VARCHAR(50),
balance DECIMAL(10, 2),
FOREIGN KEY (customer_id) REFERENCES Customers(customer_id)
);
CREATE TABLE Deposits (
deposit_id INT PRIMARY KEY,
account_id INT,
deposit_date DATE,
deposit_amount DECIMAL(10, 2),
FOREIGN KEY (account_id) REFERENCES Accounts(account_id)
);
INSERT INTO Customers (customer_id, customer_name, email, address, phone_number)
VALUES
INSERT INTO Accounts (account_id, customer_id, account_number, account_type, balance)
VALUES
(1, 1, '123456789', 'Savings', 1000.00),
(2, 2, '987654321', 'Checking', 500.00),
(3, 3, '654321098', 'Savings', 2500.00),
(4, 4, '789012345', 'Checking', 1500.00),
(5, 5, '543210987', 'Savings', 2000.00),
(6, 6, '901234567', 'Checking', 3000.00),
(7, 7, '234567890', 'Savings', 1800.00),
(8, 8, '876543210', 'Checking', 1200.00),
(9, 9, '567890123', 'Savings', 3500.00),
(10, 10, '432109876', 'Checking', 800.00),
(11, 11, '345678901', 'Savings', 4000.00),
(12, 12, '678901234', 'Checking', 2200.00),
(13, 13, '456789012', 'Savings', 1500.00),
(14, 14, '789012345', 'Checking', 3000.00),
(15, 15, '543210987', 'Savings', 2800.00);
INSERT INTO Deposits (deposit_id, account_id, deposit_date, deposit_amount)
VALUES
(1, 1, '2023-01-01', 500.00),
(2, 2, '2023-01-05', 1000.00),
(3, 3, '2023-01-10', 1500.00),
(4, 4, '2023-01-15', 2000.00),
(5, 5, '2023-01-20', 2500.00);
INSERT INTO Deposits (deposit_id, account_id, deposit_date, deposit_amount)
VALUES
(6, 2, '2023-07-10', 1200.00),
(7, 3, '2023-07-15', 1500.00),
(8, 3, '2023-07-17', 1800.00),
(9, 3, '2023-07-20', 2000.00),
(10, 4, '2023-07-25', 1600.00),
(11, 4, '2023-07-28', 1400.00),
(12, 4, '2023-07-30', 2000.00),
(13, 5, '2023-07-01', 1000.00),
(14, 5, '2023-07-05', 800.00),
(15, 5, '2023-07-08', 1200.00);
INSERT INTO Deposits (deposit_id, account_id, deposit_date, deposit_amount)
VALUES
(16, 1, '2023-06-01', 800.00),
(17, 1, '2023-06-03', 900.00),
(18, 2, '2023-06-05', 1000.00),
(19, 2, '2023-06-10', 1200.00),
(20, 3, '2023-06-15', 1500.00),
(21, 3, '2023-06-18', 1800.00),
(22, 4, '2023-06-20', 1600.00),
(23, 4, '2023-06-25', 1400.00),
(24, 5, '2023-06-30', 2000.00);
Subscribe Now and Stay Updated! 🔔