Skip to content

Instantly share code, notes, and snippets.

@mega6382
Created October 5, 2018 15:38
Show Gist options
  • Save mega6382/2fffa58db7da3feb615fb40a82b0465a to your computer and use it in GitHub Desktop.
Save mega6382/2fffa58db7da3feb615fb40a82b0465a to your computer and use it in GitHub Desktop.
a query
SELECT p.product_id,
ptc.category_id AS cat_id,
cd.name AS cat_name,
p.model AS product_code,
pd.name AS product_name,
Trim(BOTH ' ' FROM REPLACE(REPLACE(Substring(pd.description, 1, 5000),
'<p>\r \n', ''),
'</p>\r\n',
'')) AS description,
IF(Avg(r.rating) IS NULL, 'n/a', Avg(r.rating)) AS rating,
Concat('url_link', p.image) AS imag_url,
p.price,
'0' AS discount,
ss.name AS stock_status,
IF(ss.name = 'In Stock', p.quantity, 'n/a') AS stock_quantity,
IF(p.weight = 0, 'n/a', p.weight) AS weight,
IF(p.length = 0, 'n/a', p.length) AS length,
IF(p.width = 0, 'n/a', p.width) AS width,
IF(p.height = 0, 'n/a', p.height) AS height,
'n/a' AS colour,
'n/a' AS size,
'n/a' AS material,
'n/a' AS pattern
FROM `product` p
INNER JOIN `product_to_category` ptc
ON p.product_id = ptc.product_id
INNER JOIN category_description cd
ON cd.category_id = ptc.category_id
INNER JOIN product_description pd
ON p.product_id = pd.product_id
LEFT JOIN review r
ON p.product_id = r.product_id
AND r.status = 1
INNER JOIN stock_status ss
ON p.stock_status_id = ss.stock_status_id
WHERE p.product_id IN ( 62, 63, 64, 58, 53 )
GROUP BY p.product_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment