【问题标题】:prestashop: MySQL Query For product featuresprestashop: MySQL 查询产品特性
【发布时间】:2014-03-06 01:17:32
【问题描述】:

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

示例:

兼容的存储卡: - 备忘录 xD - 记忆棒 - 记忆棒 PRO - 多媒体卡 (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

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

谢谢。

【问题讨论】:

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


    【解决方案1】:

    您应该能够通过对查询进行小的调整来做到这一点。试试这个:

    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;
    

    此查询从group by 中删除fvl.value,并将group_concat() 添加到select。我还删除了f.id_feature。根据join 条件,这似乎是多余的。

    【讨论】:

    • 与此同时,我通过一些研究得到了相同的解决方案,做了一些接近相同的修改(“group_concat”)。不过,非常感谢您的帮助,我希望它会帮助一些我知道他们有很多问题的人。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多