| 6 | | select distinct f.firm_name, |
| 7 | | case when tabelaQuarter.quarter=1 then tabelaSuma.count else 0 end as prv_kvartal_suma, |
| 8 | | case when tabelaQuarter.quarter=2 then tabelaSuma.count else 0 end as vtor_kvartal, |
| 9 | | case when tabelaQuarter.quarter=3 then tabelaSuma.count else 0 end as tret_kvartal, |
| 10 | | case when tabelaQuarter.quarter=4 then tabelaSuma.count else 0 end as cetvrt_kvartal, |
| 11 | | |
| 12 | | case when tabelaQuarter.quarter=1 then tabelaSuma.sum else 0 end as prv_kvartal_suma, |
| 13 | | case when tabelaQuarter.quarter=2 then tabelaSuma.sum else 0 end as vtor_kvartal_suma, |
| 14 | | case when tabelaQuarter.quarter=3 then tabelaSuma.sum else 0 end as tret_kvartal_suma, |
| 15 | | case when tabelaQuarter.quarter=4 then tabelaSuma.sum else 0 end as cetvrt_kvartal_suma |
| 16 | | |
| 17 | | |
| | 6 | select distinct(f.firm_id) as firma, |
| | 7 | case when tabelaQuarter.quarter=1 then tabelaSuma.broj_kupeni else 0 end as prv_kvartal_kupeni, |
| | 8 | case when tabelaQuarter.quarter=2 then tabelaSuma.broj_kupeni else 0 end as vtor_kvartal_kupeni, |
| | 9 | case when tabelaQuarter.quarter=3 then tabelaSuma.broj_kupeni else 0 end as tret_kvartal_kupeni, |
| | 10 | case when tabelaQuarter.quarter=4 then tabelaSuma.broj_kupeni else 0 end as cetvrt_kvartal_kupeni, |
| | 11 | |
| | 12 | (case when tabelaQuarter.quarter=1 then tabelaSuma.sum else 0 end) as prv_kvartal_suma, |
| | 13 | (case when tabelaQuarter.quarter=2 then tabelaSuma.sum else 0 end) as vtor_kvartal_suma, |
| | 14 | (case when tabelaQuarter.quarter=3 then tabelaSuma.sum else 0 end) as tret_kvartal_suma, |
| | 15 | (case when tabelaQuarter.quarter=4 then tabelaSuma.sum else 0 end) as cetvrt_kvartal_suma |
| 26 | | select distinct f.firm_name, extract(quarter from r.reservation_date) as quarter |
| 27 | | from firm as f |
| 28 | | join auditorium as a on a.firm_id = f.firm_id |
| 29 | | join gives as g on g.auditorium_id = a.auditorium_id |
| 30 | | join movieprojection as mp on mp.projection_id = g.projection_id |
| 31 | | join reservation as r on r.projection_id = mp.projection_id |
| 32 | | |
| 33 | | ) as tabelaQuarter on tabelaQuarter.firm_name = f.firm_name |
| 34 | | |
| 35 | | join( |
| 36 | | select distinct f.firm_id,f.firm_name , a.auditorium_name as sala,sum(mp.projection_price) ,count(distinct r.reservation_id ),mp.projection_price |
| | 28 | select distinct(f2.firm_id) as firma, count(distinct r.reservation_id) as broj_kupeni,sum(mp.projection_price) as sum |
| 38 | | join movieprojection as mp on mp.projection_id = r.projection_id |
| 39 | | join gives as g on g.projection_id = mp.projection_id |
| 40 | | join auditorium as a on a.auditorium_id = g.auditorium_id |
| 41 | | join firm as f on f.firm_id = a.firm_id |
| 42 | | group by 1,2,3,6 |
| 43 | | order by sum desc |
| 44 | | ) as tabelaSuma on tabelaSuma.firm_id = f.firm_id |
| | 30 | left join movieprojection as mp on mp.projection_id = r.projection_id |
| | 31 | left join gives as g on g.projection_id = mp.projection_id |
| | 32 | left join auditorium as a on a.auditorium_id = g.auditorium_id |
| | 33 | left join firm as f2 on f2.firm_id = a.firm_id |
| | 34 | group by f2.firm_id |
| | 35 | ) as tabelaSuma on tabelaSuma.firma = f.firm_id |