| 227 | |
| 228 | === Извештај за секој филм, колку карти се продадени и колкав профит има секој филм направено, колку различни клиенти купиле карта за филмот и колку рејтинзи има секој филм === |
| 229 | {{{#!sql |
| 230 | select f.id_film, |
| 231 | coalesce(( |
| 232 | select count(distinct t.id_ticket) from tickets t |
| 233 | left join projections p on p.id_projection=t.id_projection |
| 234 | left join films f1 on f1.id_film=p.id_film |
| 235 | where f.id_film=f1.id_film |
| 236 | ),0), |
| 237 | coalesce(( |
| 238 | select sum(t.price) from tickets t |
| 239 | left join projections p on p.id_projection=t.id_projection |
| 240 | left join films f1 on f1.id_film=p.id_film |
| 241 | where f.id_film=f1.id_film |
| 242 | ),0), |
| 243 | coalesce(( |
| 244 | select count(distinct c.id_customer) from customers c |
| 245 | left join tickets t2 on t2.id_customer=c.id_customer |
| 246 | left join projections p on p.id_projection=t2.id_projection |
| 247 | left join films f1 on f1.id_film=p.id_film |
| 248 | where f.id_film=f1.id_film |
| 249 | ),0), |
| 250 | coalesce(( |
| 251 | select count(crf.rating) from customer_rates_film crf |
| 252 | left join films f2 on f2.id_film=crf.id_film |
| 253 | where f2.id_film=f.id_film |
| 254 | ),0) |
| 255 | from films f |
| 256 | }}} |