| 105 | }}} |
| 106 | |
| 107 | == Табеларен приказ на организатори со години во кои имало настани (приказ на детали за понуди трансакции и сл.) |
| 108 | {{{#!sql |
| 109 | with year_events as ( |
| 110 | select |
| 111 | distinct extract(year from (e.event_date)) as year |
| 112 | from events e |
| 113 | ) |
| 114 | select |
| 115 | u.id, |
| 116 | u.name, |
| 117 | ye.year, |
| 118 | ( |
| 119 | select |
| 120 | count(*) |
| 121 | from events as e |
| 122 | where |
| 123 | e.organizer_id = o.user_id and |
| 124 | extract(year from (e.event_date)) = ye.year |
| 125 | ) as total_events, |
| 126 | ( |
| 127 | select |
| 128 | count(*) |
| 129 | from events as e |
| 130 | join offers o2 on o2.event_id = e.id |
| 131 | where |
| 132 | e.organizer_id = o.user_id and |
| 133 | extract(year from (e.event_date)) = ye.year |
| 134 | ) as total_offers_sent, |
| 135 | ( |
| 136 | select |
| 137 | count(*) |
| 138 | from events as e |
| 139 | left join offers o2 on o2.event_id = e.id |
| 140 | join transactions as t on t.offer_id = o2.id |
| 141 | where |
| 142 | e.organizer_id = o.user_id and |
| 143 | extract(year from (e.event_date)) = ye.year |
| 144 | )as total_transactions, |
| 145 | ( |
| 146 | select |
| 147 | count(distinct o2.artist_id) |
| 148 | from events as e |
| 149 | join offers o2 on o2.event_id = e.id |
| 150 | where |
| 151 | e.organizer_id = o.user_id and |
| 152 | extract(year from (e.event_date)) = ye.year |
| 153 | ) as num_artists, --br na artisti so koi sorabotuval |
| 154 | ( |
| 155 | select |
| 156 | count(distinct o2.artist_id) |
| 157 | from events as e |
| 158 | join offers o2 on o2.event_id = e.id |
| 159 | join artists a on a.user_id = o2.artist_id and a.artist_type_id = 1 |
| 160 | where |
| 161 | e.organizer_id = o.user_id and |
| 162 | extract(year from (e.event_date)) = ye.year |
| 163 | ) as num_solo_artists, --br na solo artisti so koi sorabotuval |
| 164 | ( |
| 165 | select |
| 166 | count(distinct o2.artist_id) |
| 167 | from events as e |
| 168 | join offers o2 on o2.event_id = e.id |
| 169 | join artists a on a.user_id = o2.artist_id and a.artist_type_id = 2 |
| 170 | where |
| 171 | e.organizer_id = o.user_id and |
| 172 | extract(year from (e.event_date)) = ye.year |
| 173 | ) as num_artists, --br na duo artisti so koi sorabotuval |
| 174 | ( |
| 175 | select |
| 176 | count(distinct o2.artist_id) |
| 177 | from events as e |
| 178 | join offers o2 on o2.event_id = e.id |
| 179 | join artists a on a.user_id = o2.artist_id and a.artist_type_id = 3 |
| 180 | where |
| 181 | e.organizer_id = o.user_id and |
| 182 | extract(year from (e.event_date)) = ye.year |
| 183 | ) as num_artists --br na band artisti so koi sorabotuval |
| 184 | |
| 185 | from organizers as o |
| 186 | cross join year_events as ye |
| 187 | join users u on u.id = o.user_id |