Guest User

Untitled

a guest
Dec 15th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 9.92 KB | None | 0 0
  1. SELECT
  2.   product_id AS style_id,
  3.   color,
  4.   MaxRegularPrice,
  5.   discountprice,
  6.   marker
  7. FROM
  8.   (SELECT
  9.     product_id,
  10.     id AS style_id,
  11.     color,
  12.     MaxRegularPrice,
  13.     discountprice,
  14.     SUM(marker) AS marker
  15.   FROM
  16.     (SELECT
  17.       /* hotlistComponents::executeList */
  18.       sp_product_style.product_id,
  19.       sp_product_style.id,
  20.       sp_product_style.color,
  21.       sp_product_style.maxsaleprice AS DiscountPrice,
  22.       sp_product_style.maxregularprice AS MaxRegularPrice,
  23.       1 AS marker
  24.     FROM
  25.       (SELECT
  26.         sp_product_style.id,
  27.         sp_product_style.product_id,
  28.         sp_product_style.color,
  29.         sp_product_style.NAME,
  30.         sp_product_style.slug,
  31.         sp_product_style.is_new,
  32.         sp_product_style.product_image,
  33.         sp_product_style.sorting_order,
  34.         sp_product_style.updated_at,
  35.         sp_product_style.created_at,
  36.         MAX(
  37.           COALESCE(
  38.             ROUND(
  39.               (
  40.                 regular_price.price * sp_discount_group.multiplier
  41.               ) + .0049,
  42.               2
  43.             ),
  44.             regular_price.price
  45.           )
  46.         ) AS MaxRegularPrice,
  47.         MAX(sale_price.price) AS MaxSalePrice,
  48.         sp_product.in_stock = 1
  49.         AND sp_product.ash_city_status IN ("20", "50")
  50.         AND sp_product.assortment_check = 0
  51.         AND COUNT(sp_product_item.id) > 0
  52.         AND sp_product.STATUS != 'just_created' AS IsVisible
  53.       FROM
  54.         `sp_product`
  55.         INNER JOIN
  56.         `sp_product_style`
  57.         ON (
  58.           sp_product.sku = sp_product_style.product_id
  59.         )
  60.         INNER JOIN
  61.         `sp_product_item`
  62.         ON (
  63.           sp_product_style.id = sp_product_item.style_id
  64.           AND sp_product_item.ash_city_status IN (20, 50)
  65.         )
  66.         INNER JOIN
  67.         `sp_price` `regular_price`
  68.         ON (
  69.           (
  70.             (
  71.               (
  72.                 (
  73.                   (
  74.                     (
  75.                       sp_product_style.id = regular_price.style_id
  76.                       AND regular_price.TYPE = 'regular'
  77.                     )
  78.                     AND regular_price.currency = 2
  79.                   )
  80.                   AND regular_price.valid_from <= '2012-10-04'
  81.                 )
  82.                 AND regular_price.valid_till >= '2012-10-04'
  83.               )
  84.               AND regular_price.price > 0.01
  85.             )
  86.             AND regular_price.price < 999
  87.           )
  88.           AND regular_price.SIZE IN ('L', 'ONE', 'REG', 'LXL')
  89.         )
  90.         INNER JOIN
  91.         `sp_discount_group`
  92.         ON (
  93.           (
  94.             sp_discount_group.group_name = 'F'
  95.             AND sp_discount_group.from_q <= 0
  96.           )
  97.           AND sp_discount_group.to_q >= 0
  98.         )
  99.         INNER JOIN
  100.         `sp_customer_promo` `customer_promo`
  101.         ON (
  102.           (
  103.             customer_promo.customer_no = '610209'
  104.             AND customer_promo.valid_from <= '2012-10-04'
  105.           )
  106.           AND customer_promo.valid_till >= '2012-10-04'
  107.         )
  108.         INNER JOIN
  109.         `sp_price` `sale_price`
  110.         ON (
  111.           (
  112.             (
  113.               (
  114.                 (
  115.                   (
  116.                     (
  117.                       (
  118.                         sp_product_style.id = sale_price.style_id
  119.                         AND sale_price.pricelist_code = customer_promo.pricelist_code
  120.                       )
  121.                       AND sale_price.TYPE = 'on-sale'
  122.                     )
  123.                     AND sale_price.currency = 2
  124.                   )
  125.                   AND sale_price.valid_from <= '2012-10-04'
  126.                 )
  127.                 AND sale_price.valid_till >= '2012-10-04'
  128.               )
  129.               AND sale_price.price > 0.01
  130.             )
  131.             AND sale_price.price < 999
  132.           )
  133.           AND sale_price.SIZE = regular_price.SIZE
  134.         )
  135.       WHERE sale_price.pricelist_code IN (
  136.           'M31C',
  137.           'MDCA',
  138.           'MDCB',
  139.           'MFSC',
  140.           'MHCT',
  141.           'MHLC',
  142.           'MLCC',
  143.           'MLCT',
  144.           'MMMM',
  145.           'MSCT'
  146.         )
  147.         AND sp_product_item.quantity > 0
  148.         AND sp_product_item.warehouse_id IN ('100', '500')
  149.       GROUP BY sp_product_style.id
  150.       HAVING (
  151.           (
  152.             (MAX(sale_price.price)) > 0
  153.             AND (
  154.               MAX(
  155.                 COALESCE(
  156.                   ROUND(
  157.                     (
  158.                       regular_price.price * sp_discount_group.multiplier
  159.                     ) + .0049,
  160.                     2
  161.                   ),
  162.                   regular_price.price
  163.                 )
  164.               )
  165.             ) > 0
  166.           )
  167.           AND isvisible
  168.         )
  169.       ORDER BY sp_product.sku ASC,
  170.         sp_product_style.color ASC) AS sp_product_style
  171.       UNION
  172.       ALL
  173.       SELECT
  174.         /* hotlistComponents::executeList */
  175.         sp_product_style.product_id,
  176.         sp_product_style.id,
  177.         sp_product_style.color,
  178.         sp_product_style.maxsaleprice AS DiscountPrice,
  179.         sp_product_style.maxregularprice AS MaxRegularPrice,
  180.         2 AS marker
  181.       FROM
  182.         (SELECT
  183.           sp_product_style.id,
  184.           sp_product_style.product_id,
  185.           sp_product_style.color,
  186.           sp_product_style.NAME,
  187.           sp_product_style.slug,
  188.           sp_product_style.is_new,
  189.           sp_product_style.product_image,
  190.           sp_product_style.sorting_order,
  191.           sp_product_style.updated_at,
  192.           sp_product_style.created_at,
  193.           MAX(
  194.             COALESCE(
  195.               ROUND(
  196.                 (
  197.                   regular_price.price * sp_discount_group.multiplier
  198.                 ) + .0049,
  199.                 2
  200.               ),
  201.               regular_price.price
  202.             )
  203.           ) AS MaxRegularPrice,
  204.           MAX(sale_price.price) AS MaxSalePrice,
  205.           sp_product.in_stock = 1
  206.           AND sp_product.ash_city_status IN ("20", "50")
  207.           AND sp_product.assortment_check = 0
  208.           AND COUNT(sp_product_item.id) > 0
  209.           AND sp_product.STATUS != 'just_created' AS IsVisible
  210.         FROM
  211.           `sp_product`
  212.           INNER JOIN
  213.           `sp_product_style`
  214.           ON (
  215.             sp_product.sku = sp_product_style.product_id
  216.           )
  217.           INNER JOIN
  218.           `sp_product_item`
  219.           ON (
  220.             sp_product_style.id = sp_product_item.style_id
  221.             AND sp_product_item.ash_city_status IN (20, 50)
  222.           )
  223.           INNER JOIN
  224.           `sp_price` `regular_price`
  225.           ON (
  226.             (
  227.               (
  228.                 (
  229.                   (
  230.                     (
  231.                       (
  232.                         sp_product_style.id = regular_price.style_id
  233.                         AND regular_price.TYPE = 'regular'
  234.                       )
  235.                       AND regular_price.currency = 2
  236.                     )
  237.                     AND regular_price.valid_from <= '2012-10-04'
  238.                   )
  239.                   AND regular_price.valid_till >= '2012-10-04'
  240.                 )
  241.                 AND regular_price.price > 0.01
  242.               )
  243.               AND regular_price.price < 999
  244.             )
  245.             AND regular_price.SIZE IN ('L', 'ONE', 'REG', 'LXL')
  246.           )
  247.           INNER JOIN
  248.           `sp_discount_group`
  249.           ON (
  250.             (
  251.               sp_discount_group.group_name = 'F'
  252.               AND sp_discount_group.from_q <= 0
  253.             )
  254.             AND sp_discount_group.to_q >= 0
  255.           )
  256.           INNER JOIN
  257.           `sp_customer_promo` `customer_promo`
  258.           ON (
  259.             (
  260.               customer_promo.customer_no = '610209'
  261.               AND customer_promo.valid_from <= '2012-10-04'
  262.             )
  263.             AND customer_promo.valid_till >= '2012-10-04'
  264.           )
  265.           INNER JOIN
  266.           `sp_price` `sale_price`
  267.           ON (
  268.             (
  269.               (
  270.                 (
  271.                   (
  272.                     (
  273.                       (
  274.                         (
  275.                           sp_product_style.id = sale_price.style_id
  276.                           AND sale_price.pricelist_code = customer_promo.pricelist_code
  277.                         )
  278.                         AND sale_price.TYPE = 'on-sale'
  279.                       )
  280.                       AND sale_price.currency = 2
  281.                     )
  282.                     AND sale_price.valid_from <= '2012-10-04'
  283.                   )
  284.                   AND sale_price.valid_till >= '2012-10-04'
  285.                 )
  286.                 AND sale_price.price > 0.01
  287.               )
  288.               AND sale_price.price < 999
  289.             )
  290.             /* AND sale_price.size = regular_price.size */
  291.           )
  292.         WHERE sale_price.pricelist_code IN (
  293.             'M31C',
  294.             'MDCA',
  295.             'MDCB',
  296.             'MFSC',
  297.             'MHCT',
  298.             'MHLC',
  299.             'MLCC',
  300.             'MLCT',
  301.             'MMMM',
  302.             'MSCT'
  303.           )
  304.           AND sp_product_item.quantity > 0
  305.           AND sp_product_item.warehouse_id IN ('100', '500')
  306.         GROUP BY sp_product_style.id
  307.         HAVING (
  308.             (
  309.               (MAX(sale_price.price)) > 0
  310.               AND (
  311.                 MAX(
  312.                   COALESCE(
  313.                     ROUND(
  314.                       (
  315.                         regular_price.price * sp_discount_group.multiplier
  316.                       ) + .0049,
  317.                       2
  318.                     ),
  319.                     regular_price.price
  320.                   )
  321.                 )
  322.               ) > 0
  323.             )
  324.             AND isvisible
  325.           )
  326.         ORDER BY sp_product.sku ASC,
  327.           sp_product_style.color ASC) AS sp_product_style) X
  328.     GROUP BY product_id,
  329.       id,
  330.       MaxRegularPrice,
  331.       discountprice) X
  332.   WHERE marker <> 3
  333.   ORDER BY style_id,
  334.     color
Add Comment
Please, Sign In to add comment