mysql错误:opencart中where子句中的未知列“product\u name”

gkl3eglg  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(364)

我正在尝试使用以下mysql查询从order\U product表检索产品名称:
查询

SELECT o.order_id, 
       CONCAT(o.firstname, ' ', o.lastname) AS customer, 
       ( SELECT os.name 
         FROM order_status os 
         WHERE os.order_status_id = o.order_status_id 
         AND os.language_id = '" . (int)$this->config->get('config_language_id') . "' 
       ) AS order_status, 
       ( SELECT name 
         FROM order_product 
         WHERE order_id = o.order_id 
         LIMIT 1 
       ) AS product_name, 
       o.shipping_code, 
       o.total, 
       o.currency_code, 
       o.currency_value, 
       o.date_added, 
       o.date_modified, 
       o.telephone, 
       o.shipping_city, 
       o.order_type, 
       o.shipping_address_1 
FROM   order o 
AND    product_name LIKE '%smart tv3%'`

请帮我解决这个错误。也给我一个指引。
这就是错误,我知道了。

smdnsysy

smdnsysy1#

我通过替换查询中的和来解决了错误。:)
查询

SELECT
   o.order_id,
   CONCAT(o.firstname, ' ', o.lastname) AS customer,
  (
  SELECT
     os.name 
  FROM
     order_status os 
  WHERE
     os.order_status_id = o.order_status_id 
     AND os.language_id = '" . (int)$this->config->get('config_language_id') . "' 
)
 AS order_status,
(
  SELECT
     name 
  FROM
     order_product 
  WHERE
     order_id = o.order_id LIMIT 1 
)
 AS product_name,
 o.shipping_code,
 o.total,
 o.currency_code,
 o.currency_value,
 o.date_added,
 o.date_modified,
 o.telephone,
 o.shipping_city,
 o.order_type,
 o.shipping_address_1 
FROM
 order o 
HAVING
 product_name LIKE '%smart tv3%'`

感谢@wayneos和其他人回答我的问题:)

相关问题