72 | | select c.user_id,sum(mp.projection_price) as vkupna_potroshuvacka,u.user_name,u.user_surname from users as u |
73 | | join client as c on c.user_id = u.user_id |
74 | | join reservation as r on r.user_id = c.user_id |
75 | | and r.reservation_date between now() - interval '1 year' and now() |
76 | | join movieprojection as mp on mp.projection_id = r.projection_id |
77 | | where mp.projection_id = 12732 --?-- |
78 | | group by c.user_id,u.user_name,u.user_surname |
79 | | order by vkupna_potroshuvacka desc |
80 | | limit 1; |
| 72 | select distinct u.user_name,u.user_surname, |
| 73 | case when tabela.quarter=1 then tabela.broj_kupeni else 0 end as prv_kvartal, |
| 74 | case when tabela.quarter=2 then tabela.broj_kupeni else 0 end as vtor_kvartal, |
| 75 | case when tabela.quarter=3 then tabela.broj_kupeni else 0 end as tret_kvartal, |
| 76 | case when tabela.quarter=4 then tabela.broj_kupeni else 0 end as cetvrt_kvartal, |
| 77 | ------------------------------------------------------------------------------- |
| 78 | case when tabela.quarter=1 then tabela.suma else 0 end as prv_kvartal_suma, |
| 79 | case when tabela.quarter=2 then tabela.suma else 0 end as vtor_kvartal_suma, |
| 80 | case when tabela.quarter=3 then tabela.suma else 0 end as tret_kvartal_suma, |
| 81 | case when tabela.quarter=4 then tabela.suma else 0 end as cetvrt_kvartal_suma |
| 82 | |
| 83 | |
| 84 | from reservation as r |
| 85 | join client as c on c.user_id = r.user_id |
| 86 | join movieprojection as mp on mp.projection_id = r.projection_id |
| 87 | join users as u on u.user_id = c.user_id |
| 88 | join( |
| 89 | select distinct c2.user_id,extract(quarter from r2.reservation_date) as quarter,sum(mp.projection_price) as suma, |
| 90 | count(r2.reservation_id) as broj_kupeni |
| 91 | from reservation as r2 |
| 92 | join movieprojection as mp on mp.projection_id = r2.projection_id |
| 93 | join client as c2 on c2.user_id = r2.user_id |
| 94 | group by 1,2 |
| 95 | ) as tabela on c.user_id = tabela.user_id |