| 35 | | |
| | 35 | select distinct u.user_name,u.user_surname, |
| | 36 | case when tabela.quarter=1 then tabela.broj_kupeni else 0 end as prv_kvartal_kupeni, |
| | 37 | case when tabela.quarter=2 then tabela.broj_kupeni else 0 end as vtor_kvartal_kupeni, |
| | 38 | case when tabela.quarter=3 then tabela.broj_kupeni else 0 end as tret_kvartal_kupeni, |
| | 39 | case when tabela.quarter=4 then tabela.broj_kupeni else 0 end as cetvrt_kvartal_kupeni, |
| | 40 | ------------------------------------------------------------------------------- |
| | 41 | case when tabela.quarter=1 then tabela.suma else 0 end as prv_kvartal_suma, |
| | 42 | case when tabela.quarter=2 then tabela.suma else 0 end as vtor_kvartal_suma, |
| | 43 | case when tabela.quarter=3 then tabela.suma else 0 end as tret_kvartal_suma, |
| | 44 | case when tabela.quarter=4 then tabela.suma else 0 end as cetvrt_kvartal_suma |
| | 45 | |
| | 46 | |
| | 47 | from reservation as r |
| | 48 | join client as c on c.user_id = r.user_id |
| | 49 | join movieprojection as mp on mp.projection_id = r.projection_id |
| | 50 | join users as u on u.user_id = c.user_id |
| | 51 | join( |
| | 52 | select distinct c2.user_id,extract(quarter from r2.reservation_date) as quarter,sum(mp.projection_price) as suma, |
| | 53 | count(r2.reservation_id) as broj_kupeni |
| | 54 | from reservation as r2 |
| | 55 | join movieprojection as mp on mp.projection_id = r2.projection_id |
| | 56 | join client as c2 on c2.user_id = r2.user_id |
| | 57 | group by 1,2 |
| | 58 | ) as tabela on c.user_id = tabela.user_id |