| 65 | }}} |
| 66 | |
| 67 | == Табеларен извештај за трансакции по артисти, по години и тримесечја |
| 68 | {{{#!sql |
| 69 | with year_transactions as ( |
| 70 | select |
| 71 | distinct extract(year from (t.created_at)) as year |
| 72 | from transactions t |
| 73 | ) |
| 74 | |
| 75 | select |
| 76 | us."name", |
| 77 | yt.year, |
| 78 | ( |
| 79 | select |
| 80 | count(t.id) |
| 81 | from transactions t |
| 82 | join offers o on |
| 83 | o.artist_id = us.id and |
| 84 | t.offer_id = o.id |
| 85 | ) as total_transactions, |
| 86 | ( |
| 87 | select |
| 88 | count(t.id) |
| 89 | from transactions t |
| 90 | join offers o on |
| 91 | o.artist_id = us.id and |
| 92 | t.offer_id = o.id |
| 93 | where |
| 94 | yt.year = extract(year from (t.created_at)) and |
| 95 | extract(month from (t.created_at)) in (1,2,3) |
| 96 | ) as total_num_trans_q1, |
| 97 | ( |
| 98 | select |
| 99 | count(t.id) |
| 100 | from transactions t |
| 101 | join offers o on |
| 102 | o.artist_id = us.id and |
| 103 | t.offer_id = o.id |
| 104 | where |
| 105 | yt.year = extract(year from (t.created_at)) and |
| 106 | extract(month from (t.created_at)) in (4,5,6) |
| 107 | ) as total_num_trans_q2, |
| 108 | ( |
| 109 | select |
| 110 | count(t.id) |
| 111 | from transactions t |
| 112 | join offers o on |
| 113 | o.artist_id = us.id and |
| 114 | t.offer_id = o.id |
| 115 | where |
| 116 | yt.year = extract(year from (t.created_at)) and |
| 117 | extract(month from (t.created_at)) in (7,8,9) |
| 118 | ) as total_num_trans_q3, |
| 119 | ( |
| 120 | select |
| 121 | count(t.id) |
| 122 | from transactions t |
| 123 | join offers o on |
| 124 | o.artist_id = us.id and |
| 125 | t.offer_id = o.id |
| 126 | where |
| 127 | yt.year = extract(year from (t.created_at)) and |
| 128 | extract(month from (t.created_at)) in (10,11,12) |
| 129 | ) as total_num_trans_q4, |
| 130 | ( |
| 131 | select |
| 132 | avg(o.price) |
| 133 | from transactions t |
| 134 | join offers o on |
| 135 | o.artist_id = us.id and |
| 136 | t.offer_id = o.id |
| 137 | where |
| 138 | yt.year = extract(year from (t.created_at)) and |
| 139 | extract(month from (t.created_at)) in (1,2,3) |
| 140 | ) as avg_trans_value_q1, |
| 141 | ( |
| 142 | select |
| 143 | avg(o.price) |
| 144 | from transactions t |
| 145 | join offers o on |
| 146 | o.artist_id = us.id and |
| 147 | t.offer_id = o.id |
| 148 | where |
| 149 | yt.year = extract(year from (t.created_at)) and |
| 150 | extract(month from (t.created_at)) in (4,5,6) |
| 151 | ) as avg_trans_value_q2, |
| 152 | ( |
| 153 | select |
| 154 | avg(o.price) |
| 155 | from transactions t |
| 156 | join offers o on |
| 157 | o.artist_id = us.id and |
| 158 | t.offer_id = o.id |
| 159 | where |
| 160 | yt.year = extract(year from (t.created_at)) and |
| 161 | extract(month from (t.created_at)) in (7,8,9) |
| 162 | ) as avg_trans_value_q3, |
| 163 | ( |
| 164 | select |
| 165 | avg(o.price) |
| 166 | from transactions t |
| 167 | join offers o on |
| 168 | o.artist_id = us.id and |
| 169 | t.offer_id = o.id |
| 170 | where |
| 171 | yt.year = extract(year from (t.created_at)) and |
| 172 | extract(month from (t.created_at)) in (10,11,12) |
| 173 | ) as avg_trans_value_q4 |
| 174 | from year_transactions yt, artists ar |
| 175 | left join users us on |
| 176 | us.id = ar.user_id; |