Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.70 KB | None | 0 0
  1. SELECT
  2.     *
  3. FROM
  4.     (SELECT
  5.         p.product_id,
  6.             (SELECT
  7.                     AVG(rating) AS total
  8.                 FROM
  9.                     oc_review r1
  10.                 WHERE
  11.                     r1.product_id = p.product_id
  12.                         AND r1.status = '1'
  13.                 GROUP BY r1.product_id) AS rating,
  14.             (SELECT
  15.                     price
  16.                 FROM
  17.                     oc_product_discount pd2
  18.                 WHERE
  19.                     pd2.product_id = p.product_id
  20.                         AND pd2.customer_group_id = '1'
  21.                         AND pd2.quantity = '1'
  22.                         AND ((pd2.date_start = '0000-00-00'
  23.                         OR pd2.date_start < NOW())
  24.                         AND (pd2.date_end = '0000-00-00'
  25.                         OR pd2.date_end > NOW()))
  26.                 ORDER BY pd2.priority ASC , pd2.price ASC
  27.                 LIMIT 1) AS discount,
  28.             (SELECT
  29.                     price
  30.                 FROM
  31.                     oc_product_special ps
  32.                 WHERE
  33.                     ps.product_id = p.product_id
  34.                         AND ps.customer_group_id = '1'
  35.                         AND ((ps.date_start = '0000-00-00'
  36.                         OR ps.date_start < NOW())
  37.                         AND (ps.date_end = '0000-00-00'
  38.                         OR ps.date_end > NOW()))
  39.                 ORDER BY ps.priority ASC , ps.price ASC
  40.                 LIMIT 1) AS special
  41.     FROM
  42.         oc_category_path cp
  43.     LEFT JOIN oc_product_to_category p2c ON (cp.category_id = p2c.category_id)
  44.     LEFT JOIN oc_product p ON (p2c.product_id = p.product_id)
  45.     LEFT JOIN oc_manufacturer m ON (p.manufacturer_id = m.manufacturer_id)
  46.     LEFT JOIN oc_product_description pd ON (p.product_id = pd.product_id)
  47.     LEFT JOIN oc_product_to_store p2s ON (p.product_id = p2s.product_id)
  48.     WHERE
  49.         IF(`p`.`quantity` > 0, 7, `p`.`stock_status_id`) IN (7)
  50.             AND (FIND_IN_SET(1189, `p`.`mfilter_values`))
  51.             AND `p`.`status` = '1'
  52.             AND `p`.`date_available` <= NOW()
  53.             AND `p2c`.`category_id` IN (SELECT
  54.                 `category_id`
  55.             FROM
  56.                 `oc_category_path`
  57.             WHERE
  58.                 `path_id` IN (108))
  59.             AND `p`.`quantity` > 0
  60.             AND NOT (FIND_IN_SET(1042, `p`.`mfilter_values`))
  61.             AND pd.language_id = '2'
  62.             AND p.status = '1'
  63.             AND p.quantity > '0'
  64.             AND p.date_available <= NOW()
  65.             AND p2s.store_id = '0'
  66.             AND `cp`.`path_id` IN (108)
  67.     GROUP BY p.product_id
  68.     ORDER BY p.date_added DESC , LCASE(pd.name) DESC) AS `tmp`
  69. LIMIT 0 , 20
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement