| 98 | |
| 99 | == Прикажи ги корисниците со најголем број на трансфери на пари(број на с-ка, корисничко име, e-mail, број на трансфери и ранг во растечки редослед) |
| 100 | |
| 101 | {{{ |
| 102 | WITH transfer_frequency AS ( |
| 103 | SELECT t.s_id AS account_id, COUNT(*) AS transfer_count |
| 104 | FROM transfer t |
| 105 | GROUP BY t.s_id |
| 106 | |
| 107 | UNION ALL |
| 108 | |
| 109 | SELECT t.r_id AS account_id, COUNT(*) AS transfer_count |
| 110 | FROM transfer t |
| 111 | GROUP BY t.r_id |
| 112 | ) |
| 113 | |
| 114 | SELECT * |
| 115 | FROM ( |
| 116 | SELECT a.id AS account_id, |
| 117 | a.username, |
| 118 | a.email, |
| 119 | tf.transfer_count, |
| 120 | RANK() OVER (ORDER BY tf.transfer_count DESC) AS transfer_rank |
| 121 | FROM account a |
| 122 | JOIN transfer_frequency tf ON a.id = tf.account_id |
| 123 | ) ranked_accounts |
| 124 | WHERE transfer_rank <= 3 |
| 125 | ORDER BY transfer_rank; |
| 126 | |
| 127 | |
| 128 | }}} |
| 129 | |
| 130 | |
| 131 | |