| 1 | == Вкупен приџод по продавница во изминатите 3 месеци== |
| 2 | {{{#!sql |
| 3 | select sum(t1.Anhoch+t2.Anhoch) as Anhoch, sum(t1.Setec + t2.Setec) as Setec, sum(t1.Neptun+t2.Neptun) as Neptun |
| 4 | from |
| 5 | ( |
| 6 | select |
| 7 | sum(case when pr.store_name = 'Anhoch' then cp.quantity * pr.price else 0 end) as Anhoch, |
| 8 | sum(case when pr.store_name = 'Setec' then cp.quantity * pr.price else 0 end) as Setec, |
| 9 | sum(case when pr.store_name = 'Neptun' then cp.quantity * pr.price else 0 end) as Neptun |
| 10 | from project.order as o |
| 11 | join project.checkout as ch on o.order_id = ch.order_id |
| 12 | join project.cart as cr on cr.cart_id = ch.cart_id |
| 13 | join project.contains_product as cp on cp.cart_id = cr.cart_id |
| 14 | join project.product as pr on pr.prod_id = cp.prod_id |
| 15 | join project.store as str on pr.store_name = str.store_name |
| 16 | join project.delivery as dlv on dlv.delivery_id = o.delivery_id |
| 17 | where now() - interval '3 months' <= dlv."date" |
| 18 | ) as t1, |
| 19 | ( |
| 20 | select |
| 21 | sum(case when pr.store_name = 'Anhoch' then ccp.num_products_config * pr.price else 0 end) as Anhoch, |
| 22 | sum(case when pr.store_name = 'Setec' then ccp.num_products_config * pr.price else 0 end) as Setec, |
| 23 | sum(case when pr.store_name = 'Neptun' then ccp.num_products_config * pr.price else 0 end) as Neptun |
| 24 | from project.order as o |
| 25 | join project.orders_configuration as oc on o.order_id = oc.order_id |
| 26 | join project."Configuration" as cfg on oc.config_id = cfg.config_id |
| 27 | join project.config_contains_product as ccp on cfg.config_id = ccp.config_id |
| 28 | join project.product as pr on pr.prod_id = ccp.prod_id |
| 29 | join project.store as str on pr.store_name = str.store_name |
| 30 | join project.delivery as dlv on dlv.delivery_id = o.delivery_id |
| 31 | where now() - interval '3 months' <= dlv."date" |
| 32 | ) as t2 |
| 33 | }}} |
| 34 | |