Changes between Version 6 and Version 7 of WikiStart/Analytics
- Timestamp:
- 03/30/25 21:21:25 (5 days ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
WikiStart/Analytics
v6 v7 128 128 }}} 129 129 130 == Корисници кои направиле најголеми или примиле најголеми износи на трансфери и вкупен износ на трансфери(број на с-ка, корисничко име, e-mail, вкупен износ на сите трансфери по корисник и ранг на корисник во растечки редослед) 130 131 132 {{{ 133 WITH 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 131 138 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 147 aggregated_transfers AS ( 148 SELECT account_id, SUM(total_transfer) AS total_transfer_amount 149 FROM transfer_amount 150 GROUP BY account_id 151 ) 152 153 SELECT 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 158 FROM account a 159 LEFT JOIN aggregated_transfers at ON a.id = at.account_id 160 ORDER BY transfer_rank 161 LIMIT 3; 162 }}}