prestashop:MySQL查询产品功能

时间:2014-02-08 15:33:01

标签: mysql product concat prestashop-1.5 multiple-value

我需要在prestashop 1.5中获得产品功能,但问题是我使用修改功能使我能够为每个产品的一个功能赋予多个价值

示例:

兼容的存储卡:   - CarteMémoirexD   - 记忆棒   - Memory Stick PRO   - MultimediaCard(MMC)   - Carte Secure Digital(SD)

我收到了这个问题:

Select fl.name, fvl.value, f.id_feature
From ps_feature_lang fl Left Join
  ps_feature_product fp On fl.id_feature = fp.id_feature And fp.id_product = 291
  Left Join
  ps_feature_value_lang fvl On fp.id_feature_value = fvl.id_feature_value And
    fvl.id_lang = 5 Left Join
  ps_feature f On f.id_feature = fl.id_feature
Where fl.id_feature In (Select ps__fc_categories_features.feature_id
  From ps__fc_categories_features)
Group By fl.name, fvl.value, f.id_feature, fl.id_feature
Order By f.position

但是如果某个特定产品的特征具有多个值,则会为该特征提供多个原始值 最好的是一个查询,它将连接具有多个值的每个要素的值

在普罗旺斯的比赛中。

1 个答案:

答案 0 :(得分:0)

您应该可以通过对查询进行小幅调整来完成此操作。试试这个:

Select fl.name, group_concat(fvl.value) as values, f.id_feature
From ps_feature_lang fl Left Join
     ps_feature_product fp
     On fl.id_feature = fp.id_feature And fp.id_product = 291 Left Join
     ps_feature_value_lang fvl
     On fp.id_feature_value = fvl.id_feature_value And fvl.id_lang = 5 Left Join
     ps_feature f
     On f.id_feature = fl.id_feature
Where fl.id_feature In (Select ps__fc_categories_features.feature_id
                        From ps__fc_categories_features
                       )
Group By fl.name, fl.id_feature
Order By f.position;

此查询会从fvl.value中移除group by,并添加group_concat() select。我还删除了f.id_feature。根据{{​​1}}条件,它似乎是多余的。