Skip to content

Instantly share code, notes, and snippets.

@chanakaDe
Last active March 15, 2021 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chanakaDe/411901065a4d4230a385e2ffa3920630 to your computer and use it in GitHub Desktop.
Save chanakaDe/411901065a4d4230a385e2ffa3920630 to your computer and use it in GitHub Desktop.
Get orders for MS Power BI
select orders.id, orders.external_id, orders.created_at, order_items.article_id, manufacturers.name as manufacturer_name, articles.name as article_name, order_items.tariff_id, providers.name as provider_name, tariffs.name as tariff_name,tariffs.commission as tariff_provision, orders.external_status_order,orders.utm_partner, orders.utm_source, articles.cost_price,
(SELECT value FROM `property_values` WHERE `item_id` = `articles`.`id` AND `property_type_id` = 2 ) as device_storage,
(SELECT value FROM `property_values` WHERE `item_id` = `articles`.`id` AND `property_type_id` = 5 ) as device_color
from `orders` inner join `order_items` on `order_items`.`order_id` = `orders`.`id` inner join `articles` on `articles`.`id` = `order_items`.`article_id` inner join `manufacturers` on `manufacturers`.`id` = `articles`.`manufacturer_id` inner join `tariffs` on `tariffs`.`id` = `order_items`.`tariff_id` inner join `providers` on `providers`.`id` = `tariffs`.`provider_id`
where year(`orders`.`created_at`) = '2021' and month(`orders`.`created_at`) = '3'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment