| 1 | = Напредни извештаи од базата (SQL и складирани процедури) = |
| 2 | |
| 3 | === Извештај за сите сервиси,број на критики кои ги добиле и нивниот просечен рејтинг === |
| 4 | {{{#!sql |
| 5 | select rs.id_repair_shop as rs_id , rs.rs_name as rs_name , count(r2.review_rating) as review_count ,avg(r2.review_rating)::float as review_average |
| 6 | from project.repair_shop rs |
| 7 | left join project.repair r on r.id_repair_shop = rs.id_repair_shop |
| 8 | left join project.review r2 on r2.id_repair = r.id_repair |
| 9 | group by rs.id_repair_shop |
| 10 | }}} |
| 11 | |
| 12 | === Извештај за доставувачи за нивната најдобра нарачка. Се прикажуваат информации за доставувачот, која е неговата најдобра нарачка што ја доставил и кој производ е најскап во таа нарачка и истите се сортирани според најдобрата нарачка === |
| 13 | |
| 14 | {{{#!sql |
| 15 | select nar.deliverer, nar.deliverer_username, |
| 16 | max(nar.nar_suma) as najdobra_naracka, max(par.par_suma) as najskap_proizvod |
| 17 | from project.delivery_man d |
| 18 | left join |
| 19 | ( |
| 20 | select d.id_user as deliverer, ut.username as deliverer_username, d2.id_delivery as delivery_num |
| 21 | ,sum(p2.amount*ocp.quantity_order) as nar_suma |
| 22 | from project.delivery_man d |
| 23 | left join project.users_table ut on ut.id_user = d.id_user |
| 24 | left join project.delivery d2 on d2.id_user = d.id_user |
| 25 | left join project.order_contains_part ocp on ocp.id_order = d2.id_order |
| 26 | left join project.part p on p.id_part = ocp.id_part |
| 27 | left join project.price p2 on p2.id_part = p.id_part |
| 28 | group by (d.id_user,ut.username,delivery_num) |
| 29 | ) as nar on d.id_user = nar.deliverer |
| 30 | left join |
| 31 | ( |
| 32 | select d.id_user as deliverer, ocp.id_order as order_num,d2.id_delivery as delivery_num, p.part_name as part_name, |
| 33 | sum(p2.amount*ocp.quantity_order) as par_suma |
| 34 | from project.delivery_man d |
| 35 | left join project.users_table ut on ut.id_user = d.id_user |
| 36 | left join project.delivery d2 on d2.id_user = d.id_user |
| 37 | left join project.order_contains_part ocp on ocp.id_order = d2.id_order |
| 38 | left join project.part p on p.id_part = ocp.id_part |
| 39 | left join project.price p2 on p2.id_part = p.id_part |
| 40 | group by (d.id_user,ocp.id_order,d2.id_delivery,p.part_name) |
| 41 | ) as par on nar.deliverer = par.deliverer and nar.delivery_num = par.delivery_num |
| 42 | group by nar.deliverer,nar.deliverer_username |
| 43 | order by najdobra_naracka desc |
| 44 | }}} |
| 45 | |
| 46 | === Извештај за успешноста на еден доставувач. Се прикажуваат информации за доставувачот, број на нарачки што ги доставил и вкупна вредност на сите нарачки што ги доставил === |
| 47 | |
| 48 | {{{#!sql |
| 49 | select nar.deliverer, nar.deliverer_username, count(distinct(nar.delivery_num)) as vkupno_dostavi, |
| 50 | sum(nar.nar_suma) as vkupna_suma |
| 51 | from project.delivery_man d |
| 52 | left join |
| 53 | ( |
| 54 | select d.id_user as deliverer, ut.username as deliverer_username, d2.id_delivery as delivery_num |
| 55 | ,sum(p2.amount*ocp.quantity_order) as nar_suma |
| 56 | from project.delivery_man d |
| 57 | left join project.users_table ut on ut.id_user = d.id_user |
| 58 | left join project.delivery d2 on d2.id_user = d.id_user |
| 59 | left join project.order_contains_part ocp on ocp.id_order = d2.id_order |
| 60 | left join project.part p on p.id_part = ocp.id_part |
| 61 | left join project.price p2 on p2.id_part = p.id_part |
| 62 | group by (d.id_user,ut.username,delivery_num) |
| 63 | ) as nar on d.id_user = nar.deliverer |
| 64 | group by nar.deliverer,nar.deliverer_username |
| 65 | order by vkupna_suma desc |
| 66 | }}} |