Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions calculate_largest_expensors.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
select e.employee_id,e.first_name || ' ' || e.last_name as employee_id
,m.manager_id,
m.first_name || ' ' || m.last_name as manager_name

from EMPLOYEE e
left join
(select employee_id,sum(unit_price*quantity) as total_expensed_amount from EXPENSE group by 1)ex
on e.employee_id=ex.employee_id
left join
EMPLOYEE m
on m.employee_id=e.manager_id
where total_expensed_amount>1000
24 changes: 24 additions & 0 deletions create_employees.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE TABLE EMPLOYEE (
employee_id tinyint,
first_name varchar,
last_name varchar,
job_title varchar,
manager_id tinyint
);

INSERT INTO EMPLOYEE (
employee_id,
first_name,
last_name,
job_title,
manager_id
) VALUES
(1, 'Ian', 'James', 'CEO', 4),
(2, 'Umberto', 'Torrielli', 'CSO', 1),
(3, 'Alex', 'Jacobson', 'MD EMEA', 2),
(4, 'Darren', 'Poynton', 'CFO', 2),
(5, 'Tim', 'Beard', 'MD APAC', 2),
(6, 'Gemma', 'Dodd', 'COS', 1),
(7, 'Lisa', 'Platten', 'CHR', 6),
(8, 'Stefano', 'Camisaca', 'GM Activation', 2),
(9, 'Andrea', 'Ghibaudi', 'MD NAM', 2);
23 changes: 23 additions & 0 deletions create_expenses.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE temp_emp (
Employee_name varchar,
price DECIMAL(8, 2),
qty tinyint
);


INSERT INTO temp_emp (
Employee_name,
price,
qty
) VALUES
('Alex Jacobson', 6.50, 14),
('Alex Jacobson', 11.00, 20),
('Alex Jacobson', 2.00, 18),
('Alex Jacobson', 13.00, 75),
('Andrea Ghibaudi', 300, 1),
('Darren Poynton', 40.00, 9),
('Umberto Torrielli', 17.50, 4);

create table EXPENSE as select e.employee_id,price as unit_price,qty as quantity from temp_emp ex left outer join
EMPLOYEE e on ex.Employee_name=e.first_name || ' ' || e.last_name;
drop table temp_emp;
30 changes: 30 additions & 0 deletions create_invoices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
create table INVOICE
(supplier_id TINYINT,
invoice_ammount DECIMAL(8, 2),
due_date DATE);

create table SUPPLIER
(supplier_id TINYINT,
name VARCHAR);

INSERT INTO INVOICE (
supplier_id,
invoice_ammount,
due_date
) VALUES
(5, 6000, '2025-12-31'),
(1, 2000, '2025-11-30'),
(1, 1500, '2025-12-31'),
(2, 500, '2025-10-31'),
(3, 6000, '2025-12-31'),
(4, 4000, '2026-03-31');

INSERT INTO SUPPLIER (
supplier_id,
name
) VALUES
(5, 'Party Animals'),
(1, 'Catering Plus'),
(2, 'Dave''s Discos'),
(3, 'Entertainment tonight'),
(4, 'Ice Ice Baby');
1 change: 1 addition & 0 deletions find_manager_cycles.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select employee_id,array_agg(manager_id) as in_loop from EMPLOYEE group by 1
8 changes: 8 additions & 0 deletions generate_supplier_payment_plans.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
select
i.supplier_id,s.name as supplier_name, sum(invoice_ammount) as payment_amount, sum(invoice_ammount) over(partition by i.supplier_id) as balance_outstanding,due_date as payment_date

from INVOICE i
left outer join
SUPPLIER s
on i.supplier_id=s.supplier_id
group by 1,2,due_date