scherepanov

Untitled

Jul 22nd, 2019
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.19 KB | None | 0 0
  1. SELECT SQL_NO_CACHE COUNT(DISTINCT (entity_id))
  2. FROM (SELECT e.entity_id
  3.       FROM `catalog_product_flat_3` AS `e`
  4.                INNER JOIN
  5.            `catalog_category_product_index` AS `cat_index` ON cat_index.product_id = e.entity_id
  6.                AND cat_index.store_id = 3
  7.                AND cat_index.visibility IN (2, 4)
  8.                AND cat_index.category_id = '42'
  9.                INNER JOIN
  10.            `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id
  11.                AND price_index.website_id = '2'
  12.                AND price_index.customer_group_id = 0
  13.                LEFT JOIN
  14.            `catalog_product_entity_decimal` AS `specialPrice` ON specialPrice.`entity_id` = `e`.entity_id
  15.                AND `specialPrice`.`attribute_id` = 76
  16.                LEFT JOIN
  17.            `catalog_product_entity_datetime` AS `specialPriceFrom` ON specialPriceFrom.`entity_id` = `e`.entity_id
  18.                AND `specialPriceFrom`.`attribute_id` = 77
  19.                LEFT JOIN
  20.            `catalog_product_entity_datetime` AS `specialPriceTo` ON specialPriceTo.`entity_id` = `e`.entity_id
  21.                AND `specialPriceTo`.`attribute_id` = 78
  22.                LEFT JOIN
  23.            `catalogrule_product_price` AS `catalogRule` ON catalogRule.`product_id` = `e`.entity_id
  24.       WHERE (e.status = 1)
  25.         AND (
  26.           (
  27.                   specialPrice.value IS NOT NULL
  28.                   AND (specialPriceFrom.value < NOW()
  29.                   OR specialPriceFrom.value IS NULL
  30.                       )
  31.                   AND (
  32.                           specialPriceTo.value > NOW()
  33.                           OR specialPriceTo.value IS NULL
  34.                       )
  35.               )
  36.           )
  37.  
  38.       UNION ALL
  39.  
  40.       SELECT e.entity_id
  41.       FROM `catalog_product_flat_3` AS `e`
  42.                INNER JOIN
  43.            `catalog_category_product_index` AS `cat_index` ON cat_index.product_id = e.entity_id
  44.                AND cat_index.store_id = 3
  45.                AND cat_index.visibility IN (2, 4)
  46.                AND cat_index.category_id = '42'
  47.                INNER JOIN
  48.            `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id
  49.                AND price_index.website_id = '2'
  50.                AND price_index.customer_group_id = 0
  51.                LEFT JOIN
  52.            `catalog_product_entity_decimal` AS `specialPrice` ON specialPrice.`entity_id` = `e`.entity_id
  53.                AND `specialPrice`.`attribute_id` = 76
  54.                LEFT JOIN
  55.            `catalog_product_entity_datetime` AS `specialPriceFrom` ON specialPriceFrom.`entity_id` = `e`.entity_id
  56.                AND `specialPriceFrom`.`attribute_id` = 77
  57.                LEFT JOIN
  58.            `catalog_product_entity_datetime` AS `specialPriceTo` ON specialPriceTo.`entity_id` = `e`.entity_id
  59.                AND `specialPriceTo`.`attribute_id` = 78
  60.                LEFT JOIN
  61.            `catalogrule_product_price` AS `catalogRule` ON catalogRule.`product_id` = `e`.entity_id
  62.       WHERE (e.status = 1)
  63.         AND (
  64.           (
  65.                   `catalogRule`.website_id = 2
  66.                   AND `catalogRule`.customer_group_id = 0
  67.               )
  68.           )
  69.      ) tmp;
Advertisement
Add Comment
Please, Sign In to add comment