| 171 | |
| 172 | === Извештај за производителите на авто делови, колку делови од тој производител се продаваат за секоја четвртина од годината === |
| 173 | {{{#!sql |
| 174 | select pm.id_part_manufacturer ,pm.pm_name , |
| 175 | coalesce(fq.count_first_quarter,0) as first_quarter, coalesce(sq.count_second_quarter,0) as second_quarter, |
| 176 | coalesce(tq.count_third_quarter,0) as third_quarter, coalesce(frq.count_fourth_quarter,0) as fourth_quarter |
| 177 | from project.part_manufacturer pm |
| 178 | join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer |
| 179 | join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 180 | join project.order_table ot on ot.id_order = ocp.id_order |
| 181 | left join ( |
| 182 | select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_first_quarter |
| 183 | from project.part_manufacturer pm |
| 184 | join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer |
| 185 | join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 186 | join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date 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') |
| 187 | group by pm.id_part_manufacturer |
| 188 | ) as fq on pm.id_part_manufacturer = fq.id_part_manufacturer and pm.pm_name = fq.pm_name |
| 189 | left join ( |
| 190 | select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_second_quarter |
| 191 | from project.part_manufacturer pm |
| 192 | join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer |
| 193 | join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 194 | join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date 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') |
| 195 | group by pm.id_part_manufacturer |
| 196 | ) as sq on pm.id_part_manufacturer = sq.id_part_manufacturer and pm.pm_name = sq.pm_name |
| 197 | left join ( |
| 198 | select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_third_quarter |
| 199 | from project.part_manufacturer pm |
| 200 | join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer |
| 201 | join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 202 | join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date 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') |
| 203 | group by pm.id_part_manufacturer |
| 204 | ) as tq on pm.id_part_manufacturer = tq.id_part_manufacturer and pm.pm_name = tq.pm_name |
| 205 | left join ( |
| 206 | select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_fourth_quarter |
| 207 | from project.part_manufacturer pm |
| 208 | join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer |
| 209 | join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 210 | join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date 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') |
| 211 | group by pm.id_part_manufacturer |
| 212 | ) as frq on pm.id_part_manufacturer = frq.id_part_manufacturer and pm.pm_name = frq.pm_name |
| 213 | group by pm.id_part_manufacturer, fq.count_first_quarter, sq.count_second_quarter, tq.count_third_quarter, frq.count_fourth_quarter |
| 214 | |
| 215 | }}} |