81 | | select a.user_id, |
82 | | b.username, |
83 | | a.prihod |
84 | | from ( |
85 | | select user_id, |
86 | | sum(v.daily_rental_price * (c.end_date - c.start_date)) as prihod |
87 | | from contracts c |
88 | | join vehicles v on v.vehicle_id = c.vehicle_id |
89 | | group by c.user_id ) a |
90 | | join ( |
91 | | select c.user_id, u.username from clients as c |
92 | | join users u on u.user_id = c.user_id |
93 | | ) b on a.user_id = b.user_id |
94 | | where a.prihod = |
95 | | (select max(prihod) from ( |
96 | | select user_id,sum(v2.daily_rental_price * (c4.end_date - c4.start_date)) as prihod |
97 | | from contracts c4 |
98 | | join vehicles v2 on v2.vehicle_id = c4.vehicle_id |
99 | | group by user_id) maximprihod |
100 | | ) |
| 81 | select |
| 82 | a.user_id, |
| 83 | b.username, |
| 84 | a.prihod |
| 85 | from |
| 86 | ( |
| 87 | select |
| 88 | user_id, |
| 89 | sum(v.daily_rental_price * (c.end_date - c.start_date)) as prihod |
| 90 | from |
| 91 | contracts c |
| 92 | join vehicles v on |
| 93 | v.vehicle_id = c.vehicle_id |
| 94 | group by |
| 95 | c.user_id ) a |
| 96 | join ( |
| 97 | select |
| 98 | c.user_id, |
| 99 | u.username |
| 100 | from |
| 101 | clients as c |
| 102 | join users u on |
| 103 | u.user_id = c.user_id |
| 104 | ) b on |
| 105 | a.user_id = b.user_id |
| 106 | where |
| 107 | a.prihod = |
| 108 | ( |
| 109 | select |
| 110 | max(prihod) |
| 111 | from |
| 112 | ( |
| 113 | select |
| 114 | user_id, |
| 115 | sum(v2.daily_rental_price * (c4.end_date - c4.start_date)) as prihod |
| 116 | from |
| 117 | contracts c4 |
| 118 | join vehicles v2 on |
| 119 | v2.vehicle_id = c4.vehicle_id |
| 120 | group by |
| 121 | user_id) maximprihod |