| 1 | = Напредни извештаи од базата (SQL и складирани процедури) |
| 2 | |
| 3 | = Извештај за секоја продавница, бројот на производи во неа, вкупната вредност на производите, просечна цена по производ и вкупно направени нарачки во последните 3 месеци |
| 4 | |
| 5 | {{{#!sql |
| 6 | select os.names, os.store_id, |
| 7 | coalesce(( |
| 8 | select count(pis.product_in_store_id) |
| 9 | from online_stores as os |
| 10 | join product_in_store as pis on os.store_id=pis.store_id |
| 11 | ),0) as vkupno_proizvodi, |
| 12 | ( |
| 13 | select sum(p.price) |
| 14 | from online_stores as os |
| 15 | join product_in_store as pis on os.store_id=pis.store_id |
| 16 | join price as p on pis.product_in_store_id=p.product_in_store_id |
| 17 | |
| 18 | ) as vkupna_vrednost, |
| 19 | ( |
| 20 | select avg(p.price) |
| 21 | |
| 22 | |
| 23 | from online_stores as os |
| 24 | join product_in_store as pis on os.store_id=pis.store_id |
| 25 | join price as p on pis.product_in_store_id=p.product_in_store_id |
| 26 | |
| 27 | ) as prosek_vrednost, |
| 28 | ( |
| 29 | select count(sb.shopping_id) |
| 30 | from online_stores as os |
| 31 | join product_in_store as pis on os.store_id=pis.product_id |
| 32 | join orders as ord on pis.product_in_store_id=ord.product_in_store_id |
| 33 | join shopping_bag as sb on ord.shopping_id=sb.shopping_id |
| 34 | where sb.order_date between now() - interval '3 months' and now() |
| 35 | ) as vkupno_naracki |
| 36 | |
| 37 | |
| 38 | from online_stores as os |
| 39 | group by 1, 2 |
| 40 | |
| 41 | }}} |
| 42 | |
| 43 | == Вработен кој извршил достава на најмногу нарачки |
| 44 | {{{#!sql |
| 45 | create view vkupen_broj_naracki as |
| 46 | |
| 47 | select se.shipping_employee_id, u.user_name, u.surname, count(s.shipping_id) as broj_naracki |
| 48 | from shipping_employee as se |
| 49 | join users as u on se.user_id=u.user_id |
| 50 | join shipping as s on se.user_id=s.user_id |
| 51 | join shopping_bag as sb on s.shopping_id=sb.shopping_id |
| 52 | |
| 53 | group by 1, 2, 3; |
| 54 | |
| 55 | select vbn.shipping_employee_id, vbn.user_name, vbn.surname, vbn.broj_naracki as najmnogu_naracki |
| 56 | from vkupen_broj_naracki as vbn |
| 57 | where vbn.broj_naracki = (select max(broj_naracki) from vkupen_broj_naracki); |
| 58 | }}} |