Changes between Version 6 and Version 7 of WikiStart/Analytics


Ignore:
Timestamp:
03/30/25 21:21:25 (5 days ago)
Author:
203206
Comment:

db2

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart/Analytics

    v6 v7  
    128128}}}
    129129
     130== Корисници кои направиле најголеми или примиле најголеми износи на трансфери и вкупен износ на трансфери(број на с-ка, корисничко име, e-mail, вкупен износ на сите трансфери по корисник и ранг на корисник во растечки редослед)
    130131
     132{{{
     133WITH transfer_amount AS (
     134    SELECT t.s_id AS account_id, SUM(tr.amount) AS total_transfer
     135    FROM transfer t
     136    JOIN "transaction" tr ON t.id = tr.id
     137    GROUP BY t.s_id
    131138
     139    UNION ALL
     140
     141    SELECT t.r_id AS account_id, SUM(tr.amount) AS total_transfer
     142    FROM transfer t
     143    JOIN "transaction" tr ON t.id = tr.id
     144    GROUP BY t.r_id
     145),
     146
     147aggregated_transfers AS (
     148    SELECT account_id, SUM(total_transfer) AS total_transfer_amount
     149    FROM transfer_amount
     150    GROUP BY account_id
     151)
     152
     153SELECT a.id AS account_id,
     154       a.username,
     155       a.email,
     156       COALESCE(at.total_transfer_amount, 0) AS total_transfer_amount,
     157       RANK() OVER (ORDER BY COALESCE(at.total_transfer_amount, 0) DESC) AS transfer_rank
     158FROM account a
     159LEFT JOIN aggregated_transfers at ON a.id = at.account_id
     160ORDER BY transfer_rank
     161LIMIT 3;
     162}}}