| 102 | |
| 103 | === Извештај за сите делови, со нивни категории и производители, и количината која била нарачана од овие делови во секој од последните 3 месеци. === |
| 104 | {{{#!sql |
| 105 | select p.id_part, p.part_name, cat.category_name, pm.pm_name, f.narachani_vo_ovoj_mesec as narachani_ovoj_mesec, s.narachani_vo_prethoden_mesec as narachani_prethoden_mesec, t.narachani_vo_predprethoden_mesec as narachani_predprethoden_mesec |
| 106 | from project.part as p |
| 107 | join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer |
| 108 | join project.part_is_from_category as pifc on p.id_part = pifc.id_part |
| 109 | join project.category as cat on pifc.id_category = cat.id_category |
| 110 | left join project.order_contains_part as ocp on p.id_part = ocp.id_part |
| 111 | left join project.order_table as o on ocp.id_order = o.id_order |
| 112 | left join ( |
| 113 | select p.id_part, p.part_name, cat.category_name, pm.pm_name, |
| 114 | count(o.id_order) as narachani_vo_ovoj_mesec |
| 115 | from project.part as p |
| 116 | join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer |
| 117 | join project.part_is_from_category as pifc on p.id_part = pifc.id_part |
| 118 | join project.category as cat on pifc.id_category = cat.id_category |
| 119 | left join project.order_contains_part as ocp on p.id_part = ocp.id_part |
| 120 | left join project.order_table as o on ocp.id_order = o.id_order |
| 121 | and |
| 122 | extract(month from o.order_date) = extract(month from now()) and extract(year from o.order_date) = extract(year from now()) |
| 123 | group by p.id_part, p.part_name, cat.category_name, pm.pm_name |
| 124 | ) as f on p.id_part = f.id_part and pm.pm_name = f.pm_name |
| 125 | left join ( |
| 126 | select p.id_part, p.part_name, cat.category_name, pm.pm_name, |
| 127 | count(o.id_order) as narachani_vo_prethoden_mesec |
| 128 | from project.part as p |
| 129 | join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer |
| 130 | join project.part_is_from_category as pifc on p.id_part = pifc.id_part |
| 131 | join project.category as cat on pifc.id_category = cat.id_category |
| 132 | left join project.order_contains_part as ocp on p.id_part = ocp.id_part |
| 133 | left join project.order_table as o on ocp.id_order = o.id_order |
| 134 | and |
| 135 | extract(month from o.order_date) = extract(month from now()-interval'1 month') and extract(year from o.order_date) = extract(year from now()-interval'1 month') |
| 136 | group by p.id_part, p.part_name, cat.category_name, pm.pm_name |
| 137 | ) as s on p.id_part = s.id_part and pm.pm_name = s.pm_name |
| 138 | left join ( |
| 139 | select p.id_part, p.part_name, cat.category_name, pm.pm_name, |
| 140 | count(o.id_order) as narachani_vo_predprethoden_mesec |
| 141 | from project.part as p |
| 142 | join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer |
| 143 | join project.part_is_from_category as pifc on p.id_part = pifc.id_part |
| 144 | join project.category as cat on pifc.id_category = cat.id_category |
| 145 | left join project.order_contains_part as ocp on p.id_part = ocp.id_part |
| 146 | left join project.order_table as o on ocp.id_order = o.id_order |
| 147 | and |
| 148 | extract(month from o.order_date) = extract(month from now()-interval'2 month') and extract(year from o.order_date) = extract(year from now()-interval'2 month') |
| 149 | group by p.id_part, p.part_name, cat.category_name, pm.pm_name |
| 150 | ) as t on p.id_part = t.id_part and pm.pm_name = t.pm_name |
| 151 | group by p.id_part, p.part_name, cat.category_name, pm.pm_name, f.narachani_vo_ovoj_mesec, s.narachani_vo_prethoden_mesec, t.narachani_vo_predprethoden_mesec |
| 152 | |
| 153 | |
| 154 | |
| 155 | }}} |