61 | | }}} |
62 | | }}} |
63 | | |
64 | | == Предложување на 10те најдобро рангирани настани на даден корисник, врз база на корисниците со кои стапил во интеракција во последните 2 месеци и корисници кои имаат оставено број на реплики поголем или еднаков од вкупниот просечен на број на реплики по сите корисници |
65 | | |
66 | | {{{#!div style="font-size: 90%" |
67 | | {{{#!sql |
68 | | select title from( |
69 | | select m.title, sum(mv.stars_rated) as total |
70 | | from replies r |
71 | | join discussions d on r.discussion_id = d.discussion_id |
72 | | join replies r2 on r2.discussion_id = d.discussion_id and r2.user_id != 1 |
73 | | join users u on u.user_id = r2.user_id and |
74 | | |
75 | | ( |
76 | | select count(r3.reply_id) |
77 | | from replies r3 |
78 | | group by u.user_id |
79 | | ) >= |
80 | | ( |
81 | | |
82 | | select count(*)::float / (select count(*)::float from users) |
83 | | from replies |
84 | | ) |
85 | | |
86 | | join movie_rates mv on mv.user_id = u.user_id |
87 | | join movies m on m.movie_id = mv.movie_id |
88 | | where r.user_id = 1 and |
89 | | r.date between current_date - interval '2 months' and current_date |
90 | | group by m.title |
91 | | order by sum(mv.stars_rated) desc |
92 | | limit 15 |
93 | | ) as tabela; |
94 | | }}} |
95 | | }}} |
96 | | |
97 | | == Настан со најмногу заинтересирани купувачи во последните 100 дена |
98 | | |
99 | | {{{#!div style="font-size: 90%" |
100 | | {{{#!sql |
101 | | select e2."name", e2."date", e2.city, e2.price, q4.max_broj_zainteresirani |
102 | | from ( |
103 | | ( |
104 | | select e.id_event, count(u.id_user) as broj_na_zainteresirani_kupuvaci |
105 | | from ticket t |
106 | | join events e on t.id_event = e.id_event |
107 | | join users u on t.id_user_customer = u.id_user |
108 | | join cart c on c.id_user_customer = t.id_user_customer |
109 | | where e."date" between current_date - interval '100 days' and current_date |
110 | | group by e.id_event |
111 | | ) q1 |
112 | | |
113 | | join |
114 | | |
115 | | ( |
116 | | select max(q2.broj_na_zainteresirani_kupuvaci) as max_broj_zainteresirani |
117 | | from |
118 | | ( |
119 | | select e.id_event, count(u.id_user) as broj_na_zainteresirani_kupuvaci |
120 | | from ticket t |
121 | | join events e on t.id_event = e.id_event |
122 | | join users u on t.id_user_customer = u.id_user |
123 | | join cart c on c.id_user_customer = t.id_user_customer |
124 | | where e."date" between current_date - interval '100 days' and current_date |
125 | | group by e.id_event |
126 | | ) q2 ) q3 |
127 | | on |
128 | | q1.broj_na_zainteresirani_kupuvaci = q3.max_broj_zainteresirani) |
129 | | as q4 |
130 | | join events e2 on q4.id_event = e2.id_event |
131 | | }}} |
132 | | }}} |
133 | | |
134 | | == За секоја година, град со најголем број одржани настани |
135 | | |
136 | | {{{#!div style="font-size: 90%" |
137 | | {{{#!sql |
138 | | select q4."location", q4.max_broj_nastani |
139 | | from ( |
140 | | ( |
141 | | select extract (year from t.date) as godina, |
142 | | count(distinct e.id_event) broj_nastani, t."location" |
143 | | from ticket t |
144 | | join events e on t.id_event = e.id_event |
145 | | group by godina, t."location" |
146 | | ) q1 |
147 | | |
148 | | join |
149 | | |
150 | | ( |
151 | | select max(q2.broj_nastani) as max_broj_nastani |
152 | | from |
153 | | ( |
154 | | select extract (year from t.date) as godina, |
155 | | count(distinct e.id_event) broj_nastani, |
156 | | t."location" |
157 | | from ticket t |
158 | | join events e on t.id_event = e.id_event |
159 | | group by godina, t."location" |
160 | | ) q2 ) q3 |
161 | | on |
162 | | q1.broj_nastani = q3.max_broj_nastani) |
163 | | as q4 |
164 | | }}} |
165 | | }}} |
166 | | |
167 | | OR |
168 | | |
169 | | {{{#!div style="font-size: 90%" |
170 | | {{{#!sql |
171 | | select q4.godina, q4.city, q4.max_broj_nastani |
172 | | from ( |
173 | | ( |
174 | | select extract (year from e."date") as godina, |
175 | | count(distinct e.id_event) broj_nastani, e.city |
176 | | from events e |
177 | | group by godina, e.city |
178 | | ) q1 |
179 | | |
180 | | join |
181 | | |
182 | | ( |
183 | | select max(q2.broj_nastani) as max_broj_nastani |
184 | | from |
185 | | ( |
186 | | select extract (year from e."date") as godina, |
187 | | count(distinct e.id_event) broj_nastani, e.city |
188 | | from events e |
189 | | group by godina, e.city |
190 | | ) q2 ) q3 |
191 | | on |
192 | | q1.broj_nastani = q3.max_broj_nastani) |
193 | | as q4 |
194 | | }}} |
195 | | }}} |
196 | | |
197 | | == Артист со максимален број на одржани настани |
198 | | |
199 | | {{{#!div style="font-size: 90%" |
200 | | {{{#!sql |
201 | | select q4."name", q4.surname, q4.max_broj_nastani |
202 | | from ( |
203 | | ( |
204 | | select u."name", u.surname, count(e.id_event) as broj_nastani |
205 | | from artist a |
206 | | join users u on a.id_user = u.id_user |
207 | | join events e on a.id_user = e.id_user_artist |
208 | | group by u."name", u.surname) q1 |
209 | | |
210 | | join |
211 | | |
212 | | ( |
213 | | select max(q2.broj_nastani) as max_broj_nastani |
214 | | from |
215 | | ( |
216 | | select u."name", u.surname, count(e.id_event) as broj_nastani |
217 | | from artist a |
218 | | join users u on a.id_user = u.id_user |
219 | | join events e on a.id_user = e.id_user_artist |
220 | | group by u."name", u.surname |
221 | | ) q2 ) q3 |
222 | | on |
223 | | q1.broj_nastani = q3.max_broj_nastani) |
224 | | as q4 |
| 109 | == Настан со најмногу заинтересирани купувачи во последните 100 дена |
| 110 | |
| 111 | {{{#!div style="font-size: 90%" |
| 112 | {{{#!sql |
| 113 | select e2."name", e2."date", e2.city, e2.price, q4.max_broj_zainteresirani |
| 114 | from ( |
| 115 | ( |
| 116 | select e.id_event, count(u.id_user) as broj_na_zainteresirani_kupuvaci |
| 117 | from ticket t |
| 118 | join events e on t.id_event = e.id_event |
| 119 | join users u on t.id_user_customer = u.id_user |
| 120 | join cart c on c.id_user_customer = t.id_user_customer |
| 121 | where e."date" between current_date - interval '100 days' and current_date |
| 122 | group by e.id_event |
| 123 | ) q1 |
| 124 | |
| 125 | join |
| 126 | |
| 127 | ( |
| 128 | select max(q2.broj_na_zainteresirani_kupuvaci) as max_broj_zainteresirani |
| 129 | from |
| 130 | ( |
| 131 | select e.id_event, count(u.id_user) as broj_na_zainteresirani_kupuvaci |
| 132 | from ticket t |
| 133 | join events e on t.id_event = e.id_event |
| 134 | join users u on t.id_user_customer = u.id_user |
| 135 | join cart c on c.id_user_customer = t.id_user_customer |
| 136 | where e."date" between current_date - interval '100 days' and current_date |
| 137 | group by e.id_event |
| 138 | ) q2 ) q3 |
| 139 | on |
| 140 | q1.broj_na_zainteresirani_kupuvaci = q3.max_broj_zainteresirani) |
| 141 | as q4 |
| 142 | join events e2 on q4.id_event = e2.id_event |
| 143 | }}} |
| 144 | }}} |
| 145 | |
| 146 | == За секоја година, град со најголем број одржани настани |
| 147 | |
| 148 | {{{#!div style="font-size: 90%" |
| 149 | {{{#!sql |
| 150 | select q4."location", q4.max_broj_nastani |
| 151 | from ( |
| 152 | ( |
| 153 | select extract (year from t.date) as godina, |
| 154 | count(distinct e.id_event) broj_nastani, t."location" |
| 155 | from ticket t |
| 156 | join events e on t.id_event = e.id_event |
| 157 | group by godina, t."location" |
| 158 | ) q1 |
| 159 | |
| 160 | join |
| 161 | |
| 162 | ( |
| 163 | select max(q2.broj_nastani) as max_broj_nastani |
| 164 | from |
| 165 | ( |
| 166 | select extract (year from t.date) as godina, |
| 167 | count(distinct e.id_event) broj_nastani, |
| 168 | t."location" |
| 169 | from ticket t |
| 170 | join events e on t.id_event = e.id_event |
| 171 | group by godina, t."location" |
| 172 | ) q2 ) q3 |
| 173 | on |
| 174 | q1.broj_nastani = q3.max_broj_nastani) |
| 175 | as q4 |
| 176 | }}} |
| 177 | }}} |
| 178 | |
| 179 | OR |
| 180 | |
| 181 | {{{#!div style="font-size: 90%" |
| 182 | {{{#!sql |
| 183 | select q4.godina, q4.city, q4.max_broj_nastani |
| 184 | from ( |
| 185 | ( |
| 186 | select extract (year from e."date") as godina, |
| 187 | count(distinct e.id_event) broj_nastani, e.city |
| 188 | from events e |
| 189 | group by godina, e.city |
| 190 | ) q1 |
| 191 | |
| 192 | join |
| 193 | |
| 194 | ( |
| 195 | select max(q2.broj_nastani) as max_broj_nastani |
| 196 | from |
| 197 | ( |
| 198 | select extract (year from e."date") as godina, |
| 199 | count(distinct e.id_event) broj_nastani, e.city |
| 200 | from events e |
| 201 | group by godina, e.city |
| 202 | ) q2 ) q3 |
| 203 | on |
| 204 | q1.broj_nastani = q3.max_broj_nastani) |
| 205 | as q4 |
| 206 | }}} |
| 207 | }}} |
| 208 | |
| 209 | == Артист со максимален број на одржани настани |
| 210 | |
| 211 | {{{#!div style="font-size: 90%" |
| 212 | {{{#!sql |
| 213 | select q4."name", q4.surname, q4.max_broj_nastani |
| 214 | from ( |
| 215 | ( |
| 216 | select u."name", u.surname, count(e.id_event) as broj_nastani |
| 217 | from artist a |
| 218 | join users u on a.id_user = u.id_user |
| 219 | join events e on a.id_user = e.id_user_artist |
| 220 | group by u."name", u.surname) q1 |
| 221 | |
| 222 | join |
| 223 | |
| 224 | ( |
| 225 | select max(q2.broj_nastani) as max_broj_nastani |
| 226 | from |
| 227 | ( |
| 228 | select u."name", u.surname, count(e.id_event) as broj_nastani |
| 229 | from artist a |
| 230 | join users u on a.id_user = u.id_user |
| 231 | join events e on a.id_user = e.id_user_artist |
| 232 | group by u."name", u.surname |
| 233 | ) q2 ) q3 |
| 234 | on |
| 235 | q1.broj_nastani = q3.max_broj_nastani) |
| 236 | as q4 |
| 237 | }}} |
| 238 | }}} |
| 239 | |