48 | | == |
| 48 | == Извештај за прикажан интерес за секој филм , колку пати е резервирана проекција за тој филм во последни две недели и просечна заработка од карти за таа проекција за тој филм |
| 49 | {{{#!sql |
| 50 | select distinct mp.projection_id,m.movie_name,vkupna_brojka.vkupno,prosek.prosek_zarabotka |
| 51 | from movieprojection as mp |
| 52 | join movie as m on mp.movie_id=m.movie_id |
| 53 | |
| 54 | join( select distinct r.reservation_id, count(r.projection_id) as vkupno |
| 55 | from reservation as r |
| 56 | join movieprojection as mp2 on r.projection_id=mp2.projection_id |
| 57 | join movie as m2 on mp2.movie_id=m2.movie_id |
| 58 | where r.reservation_date between now() - interval '40 days' and now() |
| 59 | group by 1 |
| 60 | )as vkupna_brojka on vkupna_brojka.vkupno is not null |
| 61 | |
| 62 | join( select distinct r2.reservation_id,mp3.projection_id, avg(suma.sum1) as prosek_zarabotka |
| 63 | from reservation as r2 |
| 64 | join movieprojection as mp3 on r2.projection_id=mp3.projection_id |
| 65 | |
| 66 | join (select mp4.projection_id , sum(mp4.projection_price) as sum1 |
| 67 | from movieprojection as mp4 |
| 68 | group by 1 |
| 69 | )as suma on suma.sum1 is not null |
| 70 | join movie as m3 on mp3.movie_id=m3.movie_id |
| 71 | group by 1,2 |
| 72 | order by prosek_zarabotka desc |
| 73 | )as prosek on prosek.prosek_zarabotka is not null |
| 74 | }}} |