Changes between Initial Version and Version 1 of AdvancedReports


Ignore:
Timestamp:
12/09/24 23:32:50 (5 weeks ago)
Author:
211101
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReports

    v1 v1  
     1= Напредни извештаи од базата (SQL и складирани процедури)
     2
     3===== Просечно трошење во последните 3 дена
     4Просечно дневно трошење за последните три дена, земајќи ги предвид сите трансакции:
     5{{{#!sql
     6SELECT
     7    AVG(daily_spending) AS average_spending_last_3_days
     8FROM (
     9    SELECT
     10        t.date::date AS transaction_date,
     11        SUM(tb.spent_amount) AS daily_spending
     12    FROM
     13        transaction t
     14    JOIN
     15        transaction_breakdown tb ON t.transaction_id = tb.transaction_id
     16    WHERE
     17        t.date >= CURRENT_DATE - INTERVAL '2 DAY'
     18        AND t.date < CURRENT_DATE + INTERVAL '1 DAY'
     19    GROUP BY
     20        t.date::date
     21) daily_totals;
     22}}}
     23
     24===== Вкупно потрошено во тековниот месец
     25Вкупна сума на трошоци во тековниот месец
     26{{{#!sql
     27SELECT
     28    SUM(tb.spent_amount) AS total_spent
     29FROM
     30    transaction_breakdown tb
     31JOIN transaction t ON tb.transaction_id = t.transaction_id
     32WHERE
     33    EXTRACT(MONTH FROM t.date) = EXTRACT(MONTH FROM CURRENT_DATE)
     34    AND EXTRACT(YEAR FROM t.date) = EXTRACT(YEAR FROM CURRENT_DATE);
     35}}}
     36
     37===== Просечно дневно трошење за тековниот месец
     38{{{#!sql
     39SELECT
     40    SUM(tb.spent_amount) / EXTRACT(DAY FROM CURRENT_DATE) AS average_daily_spending
     41FROM
     42    transaction_breakdown tb
     43JOIN transaction t ON tb.transaction_id = t.transaction_id
     44WHERE
     45    EXTRACT(MONTH FROM t.date) = EXTRACT(MONTH FROM CURRENT_DATE)
     46    AND EXTRACT(YEAR FROM t.date) = EXTRACT(YEAR FROM CURRENT_DATE)
     47    AND t.date <= CURRENT_DATE;
     48}}}
     49
     50===== Дневен буџет до крајот на месецот
     51Дневен буџет за преостанатите денови од месецот врз основа на вкупниот баланс на сите сметки
     52{{{#!sql
     53SELECT
     54    SUM(ta.balance) / (DATE_PART('day', DATE_TRUNC('month', CURRENT_DATE + INTERVAL '1 MONTH') - INTERVAL '1 DAY') - DATE_PART('day', CURRENT_DATE)) AS daily_budget
     55FROM
     56    transaction_account ta;
     57}}}
     58
     59===== Долг на кредитна картичка од минатиот месец
     60Вкупна сума потрошена од сметките обележани како „кредитна картичка“ за минатиот месец
     61{{{#!sql
     62SELECT
     63    SUM(tb.spent_amount) AS credit_card_debt
     64FROM
     65    transaction_breakdown tb
     66JOIN transaction_account ta ON tb.transaction_account_id = ta.transaction_account_id
     67JOIN transaction t ON tb.transaction_id = t.transaction_id
     68WHERE
     69    (ta.account_name ILIKE '%кредитна%' OR ta.account_name ILIKE '%credit%')
     70    AND EXTRACT(MONTH FROM t.date) = EXTRACT(MONTH FROM CURRENT_DATE - INTERVAL '1 MONTH')
     71    AND EXTRACT(YEAR FROM t.date) = EXTRACT(YEAR FROM CURRENT_DATE - INTERVAL '1 MONTH');
     72}}}
     73
     74===== Трендови на трошење според тагови
     75Трендови на трошење за секој таг во последните шест месеци
     76{{{#!sql
     77SELECT
     78    tg.tag_name,
     79    DATE_TRUNC('month', t.date) AS month,
     80    SUM(tb.spent_amount) AS total_spent
     81FROM
     82    tag tg
     83JOIN transaction t ON tg.tag_id = t.tag_id
     84JOIN transaction_breakdown tb ON t.transaction_id = tb.transaction_id
     85WHERE
     86    t.date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '6 MONTHS')
     87GROUP BY
     88    tg.tag_name, month
     89ORDER BY
     90    tg.tag_name, month;
     91}}}
     92
     93===== Вкупно трошење според тагови
     94Вкупно трошење групирано според тагови за тековниот месец
     95{{{#!sql
     96SELECT
     97    tg.tag_name,
     98    SUM(tb.spent_amount) AS total_spent
     99FROM
     100    tag tg
     101JOIN transaction t ON tg.tag_id = t.tag_id
     102JOIN transaction_breakdown tb ON t.transaction_id = tb.transaction_id
     103WHERE
     104    EXTRACT(MONTH FROM t.date) = EXTRACT(MONTH FROM CURRENT_DATE)
     105    AND EXTRACT(YEAR FROM t.date) = EXTRACT(YEAR FROM CURRENT_DATE)
     106GROUP BY
     107    tg.tag_name
     108ORDER BY
     109    total_spent DESC;
     110}}}
     111
     112===== Сметки со највисоко вкупно трошење во изминатата година
     113{{{#!sql
     114SELECT
     115    ta.account_name,
     116    SUM(tb.spent_amount) AS total_spent
     117FROM
     118    transaction_breakdown tb
     119JOIN transaction t ON tb.transaction_id = t.transaction_id
     120JOIN transaction_account ta ON tb.transaction_account_id = ta.transaction_account_id
     121WHERE
     122    t.date >= NOW() - INTERVAL '1 YEAR'
     123GROUP BY
     124    ta.account_name
     125ORDER BY
     126    total_spent DESC
     127LIMIT 10;
     128}}}
     129
     130===== Најчести времиња за трансакции
     131Во кој час од денот корисниците најчесто вршат трансакции
     132{{{#!sql
     133SELECT
     134    EXTRACT(HOUR FROM t.date) AS transaction_hour,
     135    COUNT(*) AS transaction_count
     136FROM
     137    transaction t
     138GROUP BY
     139    transaction_hour
     140ORDER BY
     141    transaction_count DESC;
     142}}}
     143
     144===== Трансакции според тагови со највисоко трошење
     145{{{#!sql
     146SELECT
     147    tg.tag_name,
     148    SUM(tb.spent_amount) AS total_spent
     149FROM
     150    transaction_breakdown tb
     151JOIN transaction t ON tb.transaction_id = t.transaction_id
     152JOIN tag tg ON t.tag_id = tg.tag_id
     153GROUP BY
     154    tg.tag_name
     155ORDER BY
     156    total_spent DESC;
     157}}}
     158
     159===== Годишни трендови на трансакции
     160Трошења според сметки за секој квартал од тековната година
     161{{{#!sql
     162SELECT
     163    ta.account_name,
     164    CASE WHEN EXTRACT(QUARTER FROM t.date) = 1 THEN SUM(tb.spent_amount) ELSE 0 END AS q1_spent,
     165    CASE WHEN EXTRACT(QUARTER FROM t.date) = 2 THEN SUM(tb.spent_amount) ELSE 0 END AS q2_spent,
     166    CASE WHEN EXTRACT(QUARTER FROM t.date) = 3 THEN SUM(tb.spent_amount) ELSE 0 END AS q3_spent,
     167    CASE WHEN EXTRACT(QUARTER FROM t.date) = 4 THEN SUM(tb.spent_amount) ELSE 0 END AS q4_spent
     168FROM
     169    transaction_breakdown tb
     170JOIN transaction t ON tb.transaction_id = t.transaction_id
     171JOIN transaction_account ta ON tb.transaction_account_id = ta.transaction_account_id
     172WHERE
     173    EXTRACT(YEAR FROM t.date) = EXTRACT(YEAR FROM NOW())
     174GROUP BY
     175    ta.account_name, EXTRACT(QUARTER FROM t.date);
     176}}}
     177
     178===== Неактивни тагови
     179Идентификување тагови кои не биле користени во изминатиот месец
     180{{{#!sql
     181SELECT
     182    tg.tag_name
     183FROM
     184    tag tg
     185LEFT JOIN transaction t ON tg.tag_id = t.tag_id
     186WHERE
     187    t.date IS NULL OR t.date < NOW() - INTERVAL '1 MONTH';
     188}}}