Facebook
From Adam Krupa, 1 Month ago, written in SQL.
Embed
Download Paste or View Raw
Hits: 47
  1. SELECT `Product`.*,
  2. `Groups`.`id` AS `Groups.id`, `Groups`.`group_name` AS `Groups.group_name`, `Groups`.`bitwise` AS `Groups.group_bitwise`,
  3. `Groups->product_groups`.`product_id` AS `Groups.product_groups.product_id`,
  4. `Groups->product_groups`.`group_id` AS `Groups.product_groups.group_id`
  5.  
  6. FROM (
  7.         SELECT `Product`.`id`, `Product`.`name`, `Product`.`ean`, `Product`.`mpn`, `Product`.`sku`, `Product`.`brand`,
  8.                         `Product`.`uniqueId_name`, `Product`.`uniqueId_value`, `Product`.`price`, `Product`.`currency`,
  9.             `Product`.`min`, `Product`.`max`, `Product`.`mean`, `Product`.`med`, `Product`.`rank`, `Product`.`std`,
  10.             `Product`.`total_positions`, `Product`.`bitwise`, `Product`.`created_at`, `Product`.`updated_at`,
  11.             `Product`.`customer_id`,
  12.             COUNT(DISTINCT('CustomerCompetitorProducts.competitor_id')) AS `ranks`
  13.             FROM `products` AS `Product` GROUP BY `Product`.`id` LIMIT 0, 50
  14. ) AS `Product`
  15. LEFT OUTER JOIN `customer_competitor_scraping_order_products` AS
  16. `CustomerCompetitorProducts` ON `Product`.`id` = `CustomerCompetitorProducts`.`product_id`
  17. LEFT OUTER JOIN (
  18.         `product_groups` AS `Groups->product_groups`
  19.     INNER JOIN `groups` AS `Groups` ON `Groups`.`id` = `Groups->product_groups`.`group_id`
  20. ) ON `Product`.`id` = `Groups->product_groups`.`product_id` AND ((`Groups`.`customer_id` = 1));