【发布时间】:2016-03-29 18:16:08
【问题描述】:
有没有办法将这两个查询结合起来?添加另一个左连接不起作用。
select distinct
p.products_id,
p.products_image,
pd.products_name,
m.manufacturers_name,
p.manufacturers_id,
p.products_price,
p.products_tax_class_id,
IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price,
IF(s.status, s.specials_new_products_price, p.products_price) as final_price
from products_description pd,
products p
left join manufacturers m on p.manufacturers_id = m.manufacturers_id
left join specials s on p.products_id = s.products_id, products_to_categories p2c
where
p.products_status = '1'
and p.products_id = p2c.products_id
and pd.products_id = p2c.products_id
and pd.language_id = '1'
and p2c.categories_id = '17'
order by p.sort_order
//-------------------
select avg(reviews_rating) as average_rating from reviews where
products_id = '31' and reviews_status = '1'
第一个是获取产品详细信息,第二个是从评论表中获取平均评分。
【问题讨论】:
-
每个查询的结果是什么样的?合并后的结果会是什么样子?
标签: mysql