我试图在opencart中组合3个查询来构建搜索菜单,但它们总是失败并且出错。
这是示例查询
首先查询:
SELECT p.product_id,
(SELECT AVG(rating) AS total
FROM review r1
WHERE r1.product_id = p.product_id
AND r1.status = '1'
GROUP BY r1.product_id) AS rating
FROM product p
LEFT JOIN product_description pd
ON (p.product_id = pd.product_id)
LEFT JOIN product_to_store p2s
ON (p.product_id = p2s.product_id)
WHERE pd.language_id = '1'
AND p.status = '1'
AND p.date_available <= NOW()
AND p2s.store_id = '0'
AND ( LCASE(pd.name) LIKE '%dellxps13%'
OR MATCH(pd.tag) AGAINST('dellxps13')
)
OR LCASE(p.model) = 'dellxps13'
OR LCASE(p.sku) = 'dellxps13'
OR LCASE(p.upc) = 'dellxps13'
OR LCASE(p.ean) = 'dellxps13'
OR LCASE(p.jan) = 'dellxps13'
OR LCASE(p.isbn) = 'dellxps13'
OR LCASE(p.mpn) = 'dellxps13'
GROUP BY p.product_id
ORDER BY p.sort_order ASC, LCASE(pd.name) ASC
LIMIT 0, 15
第二次查询:
SELECT REPLACE (model," ","") AS 'FIND'
FROM product
WHERE REPLACE (model," ","")
它已更改为p.model(for innerjoin, p.model = product.model)
第三个查询:
SELECT REPLACE (name," ","") AS 'FIND2'
FROM product_description
WHERE REPLACE (name," ","")
它已更改为pd.name(for innerjoin, pd.name = product_description.name)
。
所以我想首先替换所有,然后select from replace like '%dellxps13%'
任何人都知道如何结合3这个查询?
这是我试图改变并得到错误
AND ((LCASE(SELECT REPLACE (pd.name," ","")) FROM product_description
WHERE LCASE (REPLACE (pd.name," ",""))) LIKE '%dellxps13%'
OR MATCH(pd.tag) AGAINST('dellxps13')
)
OR LCASE((SELECT REPLACE (p.model," ","")) FROM product WHERE LCASE (REPLACE (p.model," ",""))) = 'dellxps13'
错误1064&#39; SELECT REPLACE(pd.name,&#34;&#34;,&#34;&#34;))FROM product_description 在哪里LCASE(REPLAC&#39;在第16行。
当我不使用LCASE时出错
SELECT p.product_id,
(SELECT AVG(rating) AS total
FROM review r1
WHERE r1.product_id = p.product_id
AND r1.status = '1'
GROUP BY r1.product_id) AS rating
FROM product p
LEFT JOIN product_description pd
ON (p.product_id = pd.product_id)
LEFT JOIN product_to_store p2s
ON (p.product_id = p2s.product_id)
WHERE pd.language_id = '1'
AND p.status = '1'
AND p.date_available <= NOW()
AND p2s.store_id = '0'
AND ((SELECT REPLACE (pd.name," ","") FROM pd WHERE REPLACE (pd.name," ","") LIKE '%dellxps13%')
OR MATCH(pd.tag) AGAINST('dellxps13'))
OR (SELECT REPLACE (p.model," ","") FROM p WHERE REPLACE (p.model," ","") LIKE '%dellxps13%')
OR LCASE(p.sku) = 'dellxps13'
OR LCASE(p.upc) = 'dellxps13'
OR LCASE(p.ean) = 'dellxps13'
OR LCASE(p.jan) = 'dellxps13'
OR LCASE(p.isbn) = 'dellxps13'
OR LCASE(p.mpn) = 'dellxps13'
GROUP BY p.product_id
ORDER BY p.sort_order ASC, LCASE(pd.name) ASC
LIMIT 0, 15
错误:1146 - 表&#39; example.pd&#39;不存在