96 | | count((pedon.id_parce,pedon.id_naracka)) as broj_naracki, |
97 | | count((n.korisnicko_ime,n.id_naracka)) as kupuvac_broj_naracani, |
98 | | count((pdvm.id_magacin,pdvm.id_parce)) as dostapno_vo_magacin |
99 | | from proizvodi p |
| 94 | select k.ime , |
| 95 | coalesce(prv.zbir_1,0) as prv_kavrtal, coalesce(vtor.zbir_2,0) as vtor_kvartal, |
| 96 | coalesce(tret.zbir_3,0) as tret_kvartal, coalesce(cetvrt.zbir_4,0) as cetvrt_kvartal |
| 97 | from kompanija k |
| 98 | join proizvodi p on p.ime = k.ime |
| 99 | join parce as par on par.id_proizvod =p.id_proizvod |
| 100 | join parce_e_del_od_naracki pedon on pedon.id_parce =par.id_parce |
| 101 | join naracki as n on n.id_naracka =pedon.id_parce |
| 102 | left join ( |
| 103 | select k.ime ,p.ime_proizvod , p.kolicina as zbir_1 |
| 104 | from kompanija k |
| 105 | join proizvodi p on p.ime = k.ime |
| 106 | join parce as par on par.id_proizvod =p.id_proizvod |
| 107 | join parce_e_del_od_naracki pedon on pedon.id_parce =par.id_parce |
| 108 | join naracki as n on n.id_naracka =pedon.id_parce and n.data_na_naracka between to_date(concat('01-01-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('31-03-',extract(year from now())),'dd-mm-yyyy') |
| 109 | ) as prv on k.ime = prv.ime |
| 110 | left join ( |
| 111 | select k.ime ,p.ime_proizvod , p.kolicina as zbir_2 |
| 112 | from kompanija k |
| 113 | join proizvodi p on p.ime = k.ime |
| 114 | join parce as par on par.id_proizvod =p.id_proizvod |
| 115 | join parce_e_del_od_naracki pedon on pedon.id_parce =par.id_parce |
| 116 | join naracki as n on n.id_naracka =pedon.id_parce and n.data_na_naracka between to_date(concat('01-04-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('30-06-',extract(year from now())),'dd-mm-yyyy') |
| 117 | ) as vtor on k.ime = vtor.ime |
| 118 | left join ( |
| 119 | select k.ime ,p.ime_proizvod , p.kolicina as zbir_3 |
| 120 | from kompanija k |
| 121 | join proizvodi p on p.ime = k.ime |
| 122 | join parce as par on par.id_proizvod =p.id_proizvod |
| 123 | join parce_e_del_od_naracki pedon on pedon.id_parce =par.id_parce |
| 124 | join naracki as n on n.id_naracka =pedon.id_parce and n.data_na_naracka between to_date(concat('01-07-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('30-09-',extract(year from now())),'dd-mm-yyyy') |
| 125 | ) as tret on k.ime=tret.ime |
| 126 | left join ( |
| 127 | select k.ime ,p.ime_proizvod, p.kolicina as zbir_4 |
| 128 | from kompanija k |
| 129 | join proizvodi p on p.ime = k.ime |
| 130 | join parce as par on par.id_proizvod =p.id_proizvod |
| 131 | join parce_e_del_od_naracki pedon on pedon.id_parce =par.id_parce |
| 132 | join naracki as n on n.id_naracka =pedon.id_parce and n.data_na_naracka between to_date(concat('01-10-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('31-12-',extract(year from now())),'dd-mm-yyyy') |
| 133 | |
| 134 | ) as cetvrt on k.ime=cetvrt.ime |
| 135 | group by k.ime, prv.zbir_1, vtor.zbir_2, tret.zbir_3, cetvrt.zbir_4 |