Changes between Initial Version and Version 1 of AdvancedReport19


Ignore:
Timestamp:
08/21/26 07:03:41 (28 hours ago)
Author:
235018
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReport19

    v1 v1  
     1= List of reports which haven't been approved
     2{{{#!sql
     3CREATE OR REPLACE FUNCTION get_unapproved_reports()
     4RETURNS TABLE (
     5    report_date DATE,
     6    store_id INT,
     7    overall_profit NUMERIC,
     8    month_and_year TEXT,
     9    profit NUMERIC
     10)
     11LANGUAGE plpgsql
     12AS $$
     13BEGIN
     14    RETURN QUERY
     15    SELECT
     16        r.date AS report_date,
     17        r.store_id,
     18        r.overall_profit,
     19        r.month_and_year,
     20        r.profit
     21    FROM report r
     22    LEFT JOIN approves a
     23        ON r.date = a.date
     24        AND r.store_id = a.store_id
     25    WHERE a.date IS NULL
     26    ORDER BY
     27        r.date DESC;
     28END;
     29$$;
     30
     31}}}
     32
     33== Relational Algebra
     34- R(date, store_ID, overall_profit, monthly_profit, month_and_year, profit, sales_trend, marketing_growth, owner_signature)
     35- A(date, id)
     36
     37**JOIN approves with store owner:**
     38- J1 ← R ⟕R.date = A.date A
     39
     40**FILTER out all the reports for which no corresponding approval exists:**
     41- F1 ← σSSN IS NULL(J1)
     42
     43**Sort by report date:**
     44- R_final ← τdate DESC(F1)
     45
     46