| 60 | == Популарни артисти - рангирано според број на рецензии, тотална заработка и број на добиени понуди |
| 61 | |
| 62 | {{{#!sql |
| 63 | select |
| 64 | u.full_name, |
| 65 | u.email, |
| 66 | a.city, |
| 67 | a.country, |
| 68 | a.price_per_hour, |
| 69 | at2.name, |
| 70 | coalesce(sum(t.stripe_price),0) as earnings, |
| 71 | ( |
| 72 | select |
| 73 | count(o2.id) |
| 74 | from offers o2 |
| 75 | where o2.artist_id = a.user_id |
| 76 | ) as num_offers, |
| 77 | ( |
| 78 | (5 * (select |
| 79 | count(re.artist_id) |
| 80 | from reviews re |
| 81 | where |
| 82 | re.rating = 5 and |
| 83 | re.artist_id = a.user_id) + |
| 84 | 4 * (select |
| 85 | count(re.artist_id) |
| 86 | from reviews re |
| 87 | where |
| 88 | re.rating = 4 and |
| 89 | re.artist_id = a.user_id) + |
| 90 | 3 * (select |
| 91 | count(re.artist_id) |
| 92 | from reviews re |
| 93 | where |
| 94 | re.rating = 3 and |
| 95 | re.artist_id = a.user_id) + |
| 96 | 2 * (select |
| 97 | count(re.artist_id) |
| 98 | from reviews re |
| 99 | where |
| 100 | re.rating = 2 and |
| 101 | re.artist_id = a.user_id) + |
| 102 | 1 * (select |
| 103 | count(re.artist_id) |
| 104 | from reviews re |
| 105 | where |
| 106 | re.rating = 1 and |
| 107 | re.artist_id = a.user_id)) / |
| 108 | ((select |
| 109 | count(re.artist_id) |
| 110 | from reviews re |
| 111 | where |
| 112 | re.artist_id = a.user_id)) |
| 113 | ) |
| 114 | as average_rating |
| 115 | from users u |
| 116 | join artists a on |
| 117 | a.user_id = u.id |
| 118 | join artist_types at2 on |
| 119 | at2.id = a.artist_type_id |
| 120 | left join reviews r on |
| 121 | r.artist_id = a.user_id |
| 122 | left join offers o on |
| 123 | o.artist_id = a.user_id |
| 124 | left join transactions t on |
| 125 | t.offer_id = o.id |
| 126 | group by a.user_id, u.id, at2.id |
| 127 | order by |
| 128 | average_rating desc, |
| 129 | earnings desc, |
| 130 | num_offers asc; |
| 131 | }}} |
| 132 | |