| 67 | === Извештај за сите категории и за кој прозиводител на коли биле купени највеќе делови од таа категорија === |
| 68 | {{{#!sql |
| 69 | select c.id_category, c.category_name, cm.id_car_manufacturer , cm.cm_name , |
| 70 | count(ocp.id_part) as category_by_car |
| 71 | from project.category as c |
| 72 | left join project.part_is_from_category pifc on pifc.id_category = c.id_category |
| 73 | left join project.part p on p.id_part = pifc.id_part |
| 74 | left join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 75 | left join project.order_table ot on ot.id_order = ocp.id_order |
| 76 | left join project.users_table ut on ut.id_user = ot.id_user |
| 77 | left join project.car_sample cs on cs.id_user = ut.id_user |
| 78 | left join project.car c2 on c2.id_car = cs.id_car |
| 79 | left join project.car_manufacturer cm on cm.id_car_manufacturer = c2.id_car_manufacturer |
| 80 | group by c.id_category,cm.id_car_manufacturer |
| 81 | order by category_by_car desc |
| 82 | }}} |
| 83 | |
| 84 | === Извештај за најкупуван артикл, во која количина и од која категорија е истиот === |
| 85 | {{{#!sql |
| 86 | select c.category_name , p.part_name , coalesce(sum(ocp2.quantity_order),0) as maxkol from project.part p |
| 87 | left join project.part_is_from_category pifc on pifc.id_part = p.id_part |
| 88 | left join project.category c on c.id_category = pifc.id_category |
| 89 | left join project.order_contains_part ocp2 on ocp2.id_part = p.id_part |
| 90 | group by c.id_category , p.id_part |
| 91 | having coalesce(sum(ocp2.quantity_order), 0)=( |
| 92 | select max(maxkol) from |
| 93 | ( |
| 94 | select coalesce(sum(ocp2.quantity_order),0) as maxkol from project.part p |
| 95 | left join project.part_is_from_category pifc on pifc.id_part = p.id_part |
| 96 | left join project.category c on c.id_category = pifc.id_category |
| 97 | left join project.order_contains_part ocp2 on ocp2.id_part = p.id_part |
| 98 | group by c.id_category , p.id_part |
| 99 | ) q1 |
| 100 | ) |
| 101 | }}} |