0

即使信息表中没有与所选语言相关的行,我也会尝试使此查询包含所有 products_options_name 结果。当我现在运行查询时,只显示 products_propoptions,它在信息表中具有与所选语言相关的行。

非常感谢任何帮助。在此先感谢,巴斯

SELECT PPO.products_options_name, I.information_title, PTL.information_id, 
COUNT(PPA.products_attributes_id) as amount, 
options_id FROM products_propattributes PPA 
INNER JOIN products_propoptions PPO ON PPA.options_id = PPO.products_options_id
LEFT JOIN properties_to_information PTL ON PPA.options_id = PTL.option_id   
LEFT JOIN information I ON PTL.information_id = I.information_id
WHERE PPO.language_id = 6 AND I.language_id = 6 AND PPA.products_id = 121
GROUP BY PPA.options_id ORDER BY PPA.products_options_sort_order

表:products_propoptions

  • products_options_id
  • 语言标识
  • products_options_name
  • products_options_sort_order

表:products_propattributes

  • products_attributes_id
  • products_id
  • options_id
  • options_values_id
  • options_values_price
  • 价格前缀
  • products_options_sort_order

表:信息

  • 信息ID
  • information_group_id
  • 信息标题
  • 信息描述
  • parent_id
  • 排序
  • 可见的
  • 无索引
  • 语言标识

表:properties_to_information

  • properties_to_information_id
  • option_id
  • 信息ID
4

2 回答 2

0

这修复了它.. 包括 LEFT OUTER JOINS 以及连接中的 where 条件......谢谢.. Bas

SELECT 
PPO.products_options_name,
PTL.lexicon_id, 
I.information_title, 
COUNT(PPA.products_attributes_id) as amount, 
options_id 
FROM products_propattributes PPA  
LEFT OUTER JOIN products_propoptions PPO ON PPA.options_id = PPO.products_options_id AND PPO.language_id = 6
LEFT OUTER JOIN  properties_to_information PTL ON PPA.options_id = PTL.option_id   
LEFT OUTER JOIN information I ON PTL.lexicon_id = I.information_id  AND I.language_id = 6
WHERE PPA.products_id = 121
GROUP BY PPA.options_id ORDER BY PPA.products_options_sort_order
于 2013-06-15T20:17:16.360 回答
0

您是否尝试过将 INNER JOIN 更改为 LEFT JOIN?INNER JOIN 可能会导致查询省略您正在寻找的结果集行。

于 2013-06-15T19:15:00.767 回答