| | 1 | = Напредни извештаи од базата (SQL и складирани процедури) = |
| | 2 | |
| | 3 | Поглед за наоѓање на најнарачуваниот прозвод од категоријата Витамини |
| | 4 | // |
| | 5 | |
| | 6 | // |
| | 7 | |
| | 8 | {{{ |
| | 9 | #!python |
| | 10 | create view najnaracuvan_proizvod_od_vitamini as |
| | 11 | select order_item.product_id as "product id", product.name as "product name", sum(quantity) as "product quantity" |
| | 12 | from order_item |
| | 13 | join product on order_item.product_id = product.id |
| | 14 | join product_category on product.category_id = product_category.id |
| | 15 | where product_category.category_name = 'Vitamins' |
| | 16 | group by order_item.product_id, name |
| | 17 | order by "product quantity" desc |
| | 18 | limit 1 |
| | 19 | }}} |
| | 20 | |
| | 21 | // |
| | 22 | |
| | 23 | Поглед за наоѓање на најпрофитабилниот клиент во аптеката |
| | 24 | // |
| | 25 | |
| | 26 | // |
| | 27 | |
| | 28 | {{{ |
| | 29 | #!python |
| | 30 | create view najprofitabilen_klient as |
| | 31 | select customer.id, customer.first_name, customer.last_name, sum(product.unit_price * order_item.quantity) as "total" |
| | 32 | from orders |
| | 33 | join order_item on orders.id = order_item.order_id |
| | 34 | join product on order_item.product_id = product.id |
| | 35 | join customer on customer.id = orders.customer_id |
| | 36 | group by customer.id, customer.first_name, customer.last_name |
| | 37 | order by total desc |
| | 38 | limit 1 |
| | 39 | }}} |
| | 40 | // |
| | 41 | |