| 34 | == 5 Најпопуларни производи во изминатите 6 месеци == |
| 35 | {{{#!sql |
| 36 | select distinct p."name" as Name, p.description as description, cnt |
| 37 | from project.product as p |
| 38 | join |
| 39 | ( |
| 40 | select cp.prod_id, count(cp.prod_id) as cnt |
| 41 | from project.contains_product as cp |
| 42 | group by cp.prod_id |
| 43 | )as t1 on t1.prod_id = p.prod_id |
| 44 | join project.contains_product as ccp on ccp.prod_id = p.prod_id |
| 45 | join project.cart as crt on crt.cart_id = ccp.cart_id |
| 46 | join project.checkout as chk on chk.cart_id = crt.cart_id |
| 47 | join project.order as o on o.order_id = chk.order_id |
| 48 | join project.delivery as dlv on o.delivery_id = dlv.delivery_id |
| 49 | where dlv.status = 'Delivered' and now()-interval'6 months' <= dlv."date" |
| 50 | order by cnt desc |