Index: database/Advanced Reports for database/Approximate number of orders per client
===================================================================
--- database/Advanced Reports for database/Approximate number of orders per client	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Approximate number of orders per client	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,20 @@
+CREATE OR REPLACE FUNCTION get_approximate_orders_per_client()
+RETURNS TABLE (
+    total_clients BIGINT,
+    total_orders BIGINT,
+    approximate_orders_per_client NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        (SELECT COUNT(*) FROM client) AS total_clients,
+        (SELECT COUNT(*) FROM "order") AS total_orders,
+        ROUND(
+            (SELECT COUNT(*) FROM "order")::NUMERIC
+            / NULLIF((SELECT COUNT(*) FROM client), 0),
+            2
+        ) AS approximate_orders_per_client;
+END;
+$$;
Index: database/Advanced Reports for database/Clients ordered by number of orders.txt
===================================================================
--- database/Advanced Reports for database/Clients ordered by number of orders.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Clients ordered by number of orders.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,26 @@
+CREATE OR REPLACE FUNCTION get_clients_by_number_of_orders()
+RETURNS TABLE (
+    client_id INT,
+    client_name TEXT,
+    number_of_orders BIGINT
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        c.client_id,
+        c.name AS client_name,
+        COUNT(DISTINCT o.order_num) AS number_of_orders
+    FROM client c
+    JOIN makes_order mo
+        ON c.client_id = mo.client_id
+    JOIN "order" o
+        ON mo.order_num = o.order_num
+    GROUP BY
+        c.client_id,
+        c.name
+    ORDER BY
+        number_of_orders DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Each product's monthly sales.txt
===================================================================
--- database/Advanced Reports for database/Each product's monthly sales.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Each product's monthly sales.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,42 @@
+CREATE OR REPLACE FUNCTION get_products_monthly_sales()
+RETURNS TABLE (
+    product_code INT,
+    product_description TEXT,
+    year INT,
+    month INT,
+    number_of_orders BIGINT,
+    total_quantity_sold BIGINT,
+    total_revenue NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        p.code AS product_code,
+        p.description AS product_description,
+        EXTRACT(YEAR FROM o.last_modified_date)::INT AS year,
+        EXTRACT(MONTH FROM o.last_modified_date)::INT AS month,
+        COUNT(DISTINCT o.order_num) AS number_of_orders,
+        SUM(o.quantity) AS total_quantity_sold,
+        SUM(
+            p.price
+            * o.quantity
+            * (1 - COALESCE(o.discount, 0) / 100.0)
+        ) AS total_revenue
+    FROM product p
+    JOIN includes i
+        ON p.code = i.code
+    JOIN "order" o
+        ON i.order_num = o.order_num
+    GROUP BY
+        p.code,
+        p.description,
+        EXTRACT(YEAR FROM o.last_modified_date),
+        EXTRACT(MONTH FROM o.last_modified_date)
+    ORDER BY
+        year DESC,
+        month DESC,
+        total_revenue DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Each store's average pay.txt
===================================================================
--- database/Advanced Reports for database/Each store's average pay.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Each store's average pay.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,24 @@
+CREATE OR REPLACE FUNCTION get_stores_average_pay()
+RETURNS TABLE (
+    store_id INT,
+    store_name TEXT,
+    average_pay NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        s.store_id,
+        s.name AS store_name,
+        COALESCE(AVG(w.wage), 0) AS average_pay
+    FROM store s
+    LEFT JOIN worked w
+        ON s.store_id = w.store_id
+    GROUP BY
+        s.store_id,
+        s.name
+    ORDER BY
+        average_pay DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Each store's number of request, including how many have been solved, and how many are still in progress.txt
===================================================================
--- database/Advanced Reports for database/Each store's number of request, including how many have been solved, and how many are still in progress.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Each store's number of request, including how many have been solved, and how many are still in progress.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,40 @@
+CREATE OR REPLACE FUNCTION get_store_request_statistics()
+RETURNS TABLE (
+    store_id INT,
+    store_name TEXT,
+    total_requests BIGINT,
+    solved_requests BIGINT,
+    requests_in_progress BIGINT
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        s.store_id,
+        s.name AS store_name,
+        COUNT(r.request_num) AS total_requests,
+        COUNT(
+            CASE
+                WHEN r.customer_satisfaction IS NOT NULL
+                THEN 1
+            END
+        ) AS solved_requests,
+        COUNT(
+            CASE
+                WHEN r.customer_satisfaction IS NULL
+                THEN 1
+            END
+        ) AS requests_in_progress
+    FROM store s
+    LEFT JOIN for_store fs
+        ON s.store_id = fs.store_id
+    LEFT JOIN request r
+        ON fs.request_num = r.request_num
+    GROUP BY
+        s.store_id,
+        s.name
+    ORDER BY
+        total_requests DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Employees ordered by total hours worked and total pay.txt
===================================================================
--- database/Advanced Reports for database/Employees ordered by total hours worked and total pay.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Employees ordered by total hours worked and total pay.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,29 @@
+CREATE OR REPLACE FUNCTION get_employees_by_hours_and_pay()
+RETURNS TABLE (
+    id BIGINT,
+    employee_name TEXT,
+    total_hours_worked NUMERIC,
+    total_pay NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        e.id,
+        p.name AS employee_name,
+        COALESCE(SUM(w.working_hours), 0) AS total_hours_worked,
+        COALESCE(SUM(w.wage), 0) AS total_pay
+    FROM employees e
+    JOIN personal p
+        ON e.id = p.id
+    LEFT JOIN worked w
+        ON e.id = w.id
+    GROUP BY
+        e.id,
+        p.name
+    ORDER BY
+        total_hours_worked DESC,
+        total_pay DESC;
+END;
+$$;
Index: database/Advanced Reports for database/List of clients who haven't made an order yet.txt
===================================================================
--- database/Advanced Reports for database/List of clients who haven't made an order yet.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/List of clients who haven't made an order yet.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,21 @@
+CREATE OR REPLACE FUNCTION get_clients_without_orders()
+RETURNS TABLE (
+    client_id INT,
+    client_name TEXT,
+    email TEXT
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        c.client_id,
+        c.name AS client_name,
+        c.email
+    FROM client c
+    LEFT JOIN makes_order mo
+        ON c.client_id = mo.client_id
+    WHERE mo.order_num IS NULL
+    ORDER BY c.client_id;
+END;
+$$;
Index: database/Advanced Reports for database/List of most popular products with total number of sales.txt
===================================================================
--- database/Advanced Reports for database/List of most popular products with total number of sales.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/List of most popular products with total number of sales.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,39 @@
+CREATE OR REPLACE FUNCTION get_products_by_total_sales()
+RETURNS TABLE (
+    product_code INT,
+    product_description TEXT,
+    product_price NUMERIC,
+    number_of_orders BIGINT,
+    total_revenue NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        p.code AS product_code,
+        p.description AS product_description,
+        p.price AS product_price,
+        COUNT(DISTINCT o.order_num) AS number_of_orders,
+        COALESCE(
+            SUM(
+                p.price
+                * o.quantity
+                * (1 - COALESCE(o.discount, 0) / 100.0)
+            ),
+            0
+        ) AS total_revenue
+    FROM product p
+    LEFT JOIN includes i
+        ON p.code = i.code
+    LEFT JOIN "order" o
+        ON i.order_num = o.order_num
+    GROUP BY
+        p.code,
+        p.description,
+        p.price
+    ORDER BY
+        number_of_orders DESC,
+        total_revenue DESC;
+END;
+$$;
Index: database/Advanced Reports for database/List of products that are low on stock and high in demand.txt
===================================================================
--- database/Advanced Reports for database/List of products that are low on stock and high in demand.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/List of products that are low on stock and high in demand.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,39 @@
+CREATE OR REPLACE FUNCTION get_low_stock_high_demand_products(
+    p_stock_threshold INT,
+    p_demand_threshold INT
+)
+RETURNS TABLE (
+    product_code INT,
+    product_description TEXT,
+    current_stock INT,
+    number_of_orders BIGINT,
+    total_quantity_sold BIGINT
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        p.code AS product_code,
+        p.description AS product_description,
+        p.availability AS current_stock,
+        COUNT(DISTINCT o.order_num) AS number_of_orders,
+        COALESCE(SUM(o.quantity), 0) AS total_quantity_sold
+    FROM product p
+    JOIN includes i
+        ON p.code = i.code
+    JOIN "order" o
+        ON i.order_num = o.order_num
+    GROUP BY
+        p.code,
+        p.description,
+        p.availability
+    HAVING
+        p.availability < p_stock_threshold
+        AND COUNT(DISTINCT o.order_num) >= p_demand_threshold
+    ORDER BY
+        number_of_orders DESC,
+        total_quantity_sold DESC,
+        current_stock ASC;
+END;
+$$;
Index: database/Advanced Reports for database/List of products who have not been ordered.txt
===================================================================
--- database/Advanced Reports for database/List of products who have not been ordered.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/List of products who have not been ordered.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,62 @@
+CREATE OR REPLACE FUNCTION get_products_by_total_sales()
+RETURNS TABLE (
+    product_code INT,
+    product_description TEXT,
+    product_price NUMERIC,
+    number_of_orders BIGINT,
+    total_revenue NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        p.code AS product_code,
+        p.description AS product_description,
+        p.price AS product_price,
+        COUNT(DISTINCT o.order_num) AS number_of_orders,
+        COALESCE(
+            SUM(
+                p.price
+                * o.quantity
+                * (1 - COALESCE(o.discount, 0) / 100.0)
+            ),
+            0
+        ) AS total_revenue
+    FROM product p
+    LEFT JOIN includes i
+        ON p.code = i.code
+    LEFT JOIN "order" o
+        ON i.order_num = o.order_num
+    GROUP BY
+        p.code,
+        p.description,
+        p.price
+    ORDER BY
+        number_of_orders DESC,
+        total_revenue DESC;
+END;
+$$;
+CREATE OR REPLACE FUNCTION get_products_never_ordered()
+RETURNS TABLE (
+    product_code INT,
+    product_description TEXT,
+    product_price NUMERIC,
+    current_stock INT
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        p.code AS product_code,
+        p.description AS product_description,
+        p.price AS product_price,
+        p.availability AS current_stock
+    FROM product p
+    LEFT JOIN includes i
+        ON p.code = i.code
+    WHERE i.order_num IS NULL
+    ORDER BY p.code;
+END;
+$$;
Index: database/Advanced Reports for database/List of reports which haven't been approved.txt
===================================================================
--- database/Advanced Reports for database/List of reports which haven't been approved.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/List of reports which haven't been approved.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,27 @@
+CREATE OR REPLACE FUNCTION get_unapproved_reports()
+RETURNS TABLE (
+    report_date DATE,
+    store_id INT,
+    overall_profit NUMERIC,
+    month_and_year TEXT,
+    profit NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        r.date AS report_date,
+        r.store_id,
+        r.overall_profit,
+        r.month_and_year,
+        r.profit
+    FROM report r
+    LEFT JOIN approves a
+        ON r.date = a.date
+        AND r.store_id = a.store_id
+    WHERE a.date IS NULL
+    ORDER BY
+        r.date DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Number of product changes each employee has made in the last month.txt
===================================================================
--- database/Advanced Reports for database/Number of product changes each employee has made in the last month.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Number of product changes each employee has made in the last month.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,31 @@
+CREATE OR REPLACE FUNCTION get_employee_product_changes_last_month()
+RETURNS TABLE (
+    id BIGINT,
+    employee_name TEXT,
+    number_of_product_changes BIGINT
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        e.id,
+        p.name AS employee_name,
+        COUNT(DISTINCT mc.date_and_time) AS number_of_product_changes
+    FROM employees e
+    JOIN personal p
+        ON e.id = p.id
+    LEFT JOIN makes_change mc
+        ON e.id = mc.id
+    LEFT JOIN change ch
+        ON mc.date_and_time = ch.date_and_time
+    WHERE
+        mc.date_and_time >= date_trunc('month', CURRENT_DATE) - INTERVAL '1 month'
+        AND mc.date_and_time < date_trunc('month', CURRENT_DATE)
+    GROUP BY
+        e.id,
+        p.name
+    ORDER BY
+        number_of_product_changes DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Orders ordered by order total from highest to lowest.txt
===================================================================
--- database/Advanced Reports for database/Orders ordered by order total from highest to lowest.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Orders ordered by order total from highest to lowest.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,45 @@
+CREATE OR REPLACE FUNCTION get_orders_by_total()
+RETURNS TABLE (
+    order_num INT,
+    client_id INT,
+    client_name TEXT,
+    order_quantity INT,
+    order_status TEXT,
+    payment_method TEXT,
+    discount NUMERIC,
+    order_total NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        o.order_num,
+        c.client_id,
+        c.name,
+        o.quantity,
+        o.status,
+        o.payment_method,
+        COALESCE(o.discount, 0) AS discount,
+        SUM(p.price * o.quantity)
+            * (1 - COALESCE(o.discount, 0) / 100) AS order_total
+    FROM "order" o
+    JOIN makes_order mo
+        ON o.order_num = mo.order_num
+    JOIN client c
+        ON mo.client_id = c.client_id
+    JOIN includes i
+        ON o.order_num = i.order_num
+    JOIN product p
+        ON i.code = p.code
+    GROUP BY
+        o.order_num,
+        c.client_id,
+        c.name,
+        o.quantity,
+        o.status,
+        o.payment_method,
+        o.discount
+    ORDER BY order_total DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Products ordered by number of orders from highest to lowest.txt
===================================================================
--- database/Advanced Reports for database/Products ordered by number of orders from highest to lowest.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Products ordered by number of orders from highest to lowest.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,29 @@
+CREATE OR REPLACE FUNCTION get_products_by_number_of_orders()
+RETURNS TABLE (
+    product_code INT,
+    product_description TEXT,
+    product_price NUMERIC,
+    number_of_orders BIGINT
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        p.code AS product_code,
+        p.description AS product_description,
+        p.price AS product_price,
+        COUNT(DISTINCT o.order_num) AS number_of_orders
+    FROM product p
+    JOIN includes i
+        ON p.code = i.code
+    JOIN "order" o
+        ON i.order_num = o.order_num
+    GROUP BY
+        p.code,
+        p.description,
+        p.price
+    ORDER BY
+        number_of_orders DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Store with highest revenue growth in the last calendar year.txt
===================================================================
--- database/Advanced Reports for database/Store with highest revenue growth in the last calendar year.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Store with highest revenue growth in the last calendar year.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,74 @@
+CREATE OR REPLACE FUNCTION get_store_with_highest_revenue_growth()
+RETURNS TABLE (
+    store_id INT,
+    store_name TEXT,
+    previous_year_revenue NUMERIC,
+    last_year_revenue NUMERIC,
+    revenue_growth NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    WITH yearly_revenue AS (
+        SELECT
+            s.store_id,
+            s.name AS store_name,
+            EXTRACT(YEAR FROM o.last_modified_date)::INT AS year,
+            SUM(
+                p.price
+                * o.quantity
+                * (1 - COALESCE(o.discount, 0) / 100.0)
+            ) AS total_revenue
+        FROM store s
+        JOIN sells se
+            ON s.store_id = se.store_id
+        JOIN product p
+            ON se.code = p.code
+        JOIN includes i
+            ON p.code = i.code
+        JOIN "order" o
+            ON i.order_num = o.order_num
+        WHERE o.last_modified_date >=
+              date_trunc('year', CURRENT_DATE) - INTERVAL '2 years'
+          AND o.last_modified_date <
+              date_trunc('year', CURRENT_DATE)
+        GROUP BY
+            s.store_id,
+            s.name,
+            EXTRACT(YEAR FROM o.last_modified_date)
+    ),
+    revenue_comparison AS (
+        SELECT
+            store_id,
+            store_name,
+            MAX(
+                CASE
+                    WHEN year = EXTRACT(YEAR FROM CURRENT_DATE)::INT - 2
+                    THEN total_revenue
+                    ELSE 0
+                END
+            ) AS previous_year_revenue,
+            MAX(
+                CASE
+                    WHEN year = EXTRACT(YEAR FROM CURRENT_DATE)::INT - 1
+                    THEN total_revenue
+                    ELSE 0
+                END
+            ) AS last_year_revenue
+        FROM yearly_revenue
+        GROUP BY
+            store_id,
+            store_name
+    )
+    SELECT
+        store_id,
+        store_name,
+        previous_year_revenue,
+        last_year_revenue,
+        last_year_revenue - previous_year_revenue AS revenue_growth
+    FROM revenue_comparison
+    ORDER BY revenue_growth DESC
+    LIMIT 1;
+END;
+$$;
Index: database/Advanced Reports for database/Stores ordered by highest approximate product review.txt
===================================================================
--- database/Advanced Reports for database/Stores ordered by highest approximate product review.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Stores ordered by highest approximate product review.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,32 @@
+CREATE OR REPLACE FUNCTION get_stores_by_average_review()
+RETURNS TABLE (
+    store_id INT,
+    store_name TEXT,
+    average_review NUMERIC,
+    number_of_reviews BIGINT
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        s.store_id,
+        s.name AS store_name,
+        COALESCE(AVG(r.rating), 0) AS average_review,
+        COUNT(r.order_num) AS number_of_reviews
+    FROM store s
+    LEFT JOIN sells se
+        ON s.store_id = se.store_id
+    LEFT JOIN includes i
+        ON se.code = i.code
+    LEFT JOIN "order" o
+        ON i.order_num = o.order_num
+    LEFT JOIN review r
+        ON o.order_num = r.order_num
+    GROUP BY
+        s.store_id,
+        s.name
+    ORDER BY
+        average_review DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Stores ordered by monthly profit including monthly revenue growth.txt
===================================================================
--- database/Advanced Reports for database/Stores ordered by monthly profit including monthly revenue growth.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Stores ordered by monthly profit including monthly revenue growth.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,64 @@
+CREATE OR REPLACE FUNCTION get_stores_by_monthly_profit_and_revenue_growth()
+RETURNS TABLE (
+    store_id INT,
+    store_name TEXT,
+    month_and_year TEXT,
+    monthly_profit NUMERIC,
+    previous_month_revenue NUMERIC,
+    current_month_revenue NUMERIC,
+    revenue_growth NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    WITH monthly_revenue AS (
+        SELECT
+            s.store_id,
+            s.name AS store_name,
+            DATE_TRUNC('month', o.last_modified_date) AS month_date,
+            SUM(
+                p.price
+                * o.quantity
+                * (1 - COALESCE(o.discount, 0) / 100.0)
+            ) AS revenue
+        FROM store s
+        JOIN sells se
+            ON s.store_id = se.store_id
+        JOIN product p
+            ON se.code = p.code
+        JOIN includes i
+            ON p.code = i.code
+        JOIN "order" o
+            ON i.order_num = o.order_num
+        GROUP BY
+            s.store_id,
+            s.name,
+            DATE_TRUNC('month', o.last_modified_date)
+    ),
+    revenue_with_previous AS (
+        SELECT
+            store_id,
+            store_name,
+            month_date,
+            revenue,
+            LAG(revenue) OVER (
+                PARTITION BY store_id
+                ORDER BY month_date
+            ) AS previous_month_revenue
+        FROM monthly_revenue
+    )
+    SELECT
+        store_id,
+        store_name,
+        TO_CHAR(month_date, 'YYYY-MM') AS month_and_year,
+        revenue AS monthly_profit,
+        COALESCE(previous_month_revenue, 0) AS previous_month_revenue,
+        revenue AS current_month_revenue,
+        revenue - COALESCE(previous_month_revenue, 0) AS revenue_growth
+    FROM revenue_with_previous
+    ORDER BY
+        monthly_profit DESC,
+        revenue_growth DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Stores ordered by total revenue in the last calendar year from highest to lowest.txt
===================================================================
--- database/Advanced Reports for database/Stores ordered by total revenue in the last calendar year from highest to lowest.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Stores ordered by total revenue in the last calendar year from highest to lowest.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,49 @@
+CREATE OR REPLACE FUNCTION get_stores_by_last_calendar_year_revenue()
+RETURNS TABLE (
+    store_id INT,
+    store_name TEXT,
+    number_of_orders BIGINT,
+    total_quantity_sold BIGINT,
+    total_revenue NUMERIC
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        s.store_id,
+        s.name AS store_name,
+        COUNT(DISTINCT o.order_num) AS number_of_orders,
+        COALESCE(SUM(o.quantity), 0) AS total_quantity_sold,
+        COALESCE(
+            SUM(
+                p.price
+                * o.quantity
+                * (1 - COALESCE(o.discount, 0) / 100.0)
+            ),
+            0
+        ) AS total_revenue
+    FROM store s
+    LEFT JOIN sells se
+        ON s.store_id = se.store_id
+    LEFT JOIN product p
+        ON se.code = p.code
+    LEFT JOIN includes i
+        ON p.code = i.code
+    LEFT JOIN "order" o
+        ON i.order_num = o.order_num
+        AND o.last_modified_date >= DATE_TRUNC(
+            'year',
+            CURRENT_DATE
+        ) - INTERVAL '1 year'
+        AND o.last_modified_date < DATE_TRUNC(
+            'year',
+            CURRENT_DATE
+        )
+    GROUP BY
+        s.store_id,
+        s.name
+    ORDER BY
+        total_revenue DESC;
+END;
+$$;
Index: database/Advanced Reports for database/Top 10 employees who have answered the most amount of request in the last month.txt
===================================================================
--- database/Advanced Reports for database/Top 10 employees who have answered the most amount of request in the last month.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Top 10 employees who have answered the most amount of request in the last month.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,31 @@
+CREATE OR REPLACE FUNCTION get_top_10_employees_by_requests_last_month()
+RETURNS TABLE (
+    id BIGINT,
+    employee_name TEXT,
+    number_of_requests BIGINT
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        e.id,
+        p.name AS employee_name,
+        COUNT(DISTINCT a.request_num) AS number_of_requests
+    FROM employees e
+    JOIN personal p
+        ON e.id = p.id
+    JOIN answers a
+        ON e.id = a.id
+    JOIN request r
+        ON a.request_num = r.request_num
+    WHERE r.date_and_time >= date_trunc('month', CURRENT_DATE) - INTERVAL '1 month'
+      AND r.date_and_time < date_trunc('month', CURRENT_DATE)
+    GROUP BY
+        e.id,
+        p.name
+    ORDER BY
+        number_of_requests DESC
+    LIMIT 10;
+END;
+$$;
