| 15 | |
| 16 | === Извештај за сите категории, нивните најмногу нарачани продукти и бројот на нарачки за продуктот |
| 17 | {{{ |
| 18 | select |
| 19 | category.category_name as Category, |
| 20 | product.product_name as Product_Name, |
| 21 | count(order_table_contains_product.product_id) as Number_of_orders |
| 22 | from |
| 23 | category |
| 24 | join product_is_in_category on category.category_id = product_is_in_category.category_id |
| 25 | join product on product_is_in_category.product_id = product.product_id |
| 26 | join order_table_contains_product on product.product_id = order_table_contains_product.product_id |
| 27 | group by |
| 28 | category.category_id, |
| 29 | category.category_name, |
| 30 | product.product_name |
| 31 | having |
| 32 | count(order_table_contains_product.product_id) = ( |
| 33 | select |
| 34 | count(*) |
| 35 | from |
| 36 | order_table_contains_product |
| 37 | join product on order_table_contains_product.product_id = product.product_id |
| 38 | join product_is_in_category on product.product_id = product_is_in_category.product_id |
| 39 | where |
| 40 | product_is_in_category.category_id = category.category_id |
| 41 | group by |
| 42 | order_table_contains_product.product_id |
| 43 | ) |
| 44 | }}} |