[Magento SQL]查询出可配置产品(父产品)、子产品的价格,和与子产品对应属性的差价
2017-10-14 10:56
429 查看
/* 查询出可配置产品(父产品)、子产品的价格,和与子产品对应属性的差价 在我们的项目中 attribute_id=76是为了查询产品的special price价格; parent_id=1459我们查询是id为1459的这个可配置产品 */ SELECT t1.child_id,t2.value,t3.value as c_price,t4.pricing_value,t4.value as p_price,t5.sku FROM catalog_product_relation AS t1 LEFT JOIN catalog_product_entity_int AS t2 ON t2.entity_id=t1.child_id LEFT JOIN catalog_product_entity_decimal AS t3 ON t3.entity_id=t1.child_id left join ( SELECT t1.product_id,t1.attribute_id, t2.value_index,t2.pricing_value,t3.value FROM catalog_product_super_attribute AS t1 LEFT JOIN catalog_product_super_attribute_pricing AS t2 ON t2.product_super_attribute_id=t1.product_super_attribute_id LEFT JOIN catalog_product_entity_decimal AS t3 ON t3.entity_id=t1.product_id WHERE t1.product_id=1459 AND t2.pricing_value IS NOT NULL AND t3.attribute_id=76 ) as t4 on t4.value_index=t2.value LEFT JOIN catalog_product_entity AS t5 ON t5.entity_id=t1.child_id WHERE t1.parent_id=1459 AND t3.attribute_id=76 AND t2.attribute_id IN (SELECT attribute_id FROM catalog_product_super_attribute WHERE product_id=1459) AND t2.value IN (SELECT t2.value_index FROM catalog_product_super_attribute AS t1 LEFT JOIN catalog_product_super_attribute_pricing AS t2 ON t2.product_super_attribute_id=t1.product_super_attribute_id WHERE t1.product_id=1459);
这样就查询出了 差价
pricing_value、父产品价格
p_price、子产品价格
c_price和 子产品SKU。
要注意产品和对应属性差值的组合:n种组合查询的总记录也是n。
#最后如果需要 “差价+父产品价格!=子产品价格” 的记录 #也就是在上面结果集上还需要多一层处理 #可以用到HAVING ,但HAVING 之前必须有GROUP BY #这里我们要所有字段联合起来 作为GROUP BY的字段,利用msyql的CONCAT()函数 SELECT t1.child_id,t2.value,t3.value as c_price,t4.pricing_value,t4.value as p_price,t5.sku,CONCAT(t1.child_id,t2.value,t3.value,t4.pricing_value,t4.value,t5.sku) as g FROM catalog_product_relation AS t1 LEFT JOIN catalog_product_entity_int AS t2 ON t2.entity_id=t1.child_id LEFT JOIN catalog_product_entity_decimal AS t3 ON t3.entity_id=t1.child_id left join ( SELECT t1.product_id,t1.attribute_id, t2.value_index,t2.pricing_value,t3.value FROM catalog_product_super_attribute AS t1 LEFT JOIN catalog_product_super_attribute_pricing AS t2 ON t2.product_super_attribute_id=t1.product_super_attribute_id LEFT JOIN catalog_product_entity_decimal AS t3 ON t3.entity_id=t1.product_id WHERE t1.product_id=1459 AND t2.pricing_value IS NOT NULL AND t3.attribute_id=76 ) as t4 on t4.value_index=t2.value LEFT JOIN catalog_product_entity AS t5 ON t5.entity_id=t1.child_id WHERE t1.parent_id=1459 AND t3.attribute_id=76 AND t2.attribute_id IN (SELECT attribute_id FROM catalog_product_super_attribute WHERE product_id=1459) AND t2.value IN (SELECT t2.value_index FROM catalog_product_super_attribute AS t1 LEFT JOIN catalog_product_super_attribute_pricing AS t2 ON t2.product_super_attribute_id=t1.product_super_attribute_id WHERE t1.product_id=1459) GROUP BY g;
#在上面结果集的基础之上判断:差价+父产品价格!=子产品价格 # HAVING pricing_value+p_price!=c_price
如果最后结果是只是需要子产品的SKU,可以在套一层查询,然后
GROUP BY就去掉重复的子产品SKU了:
SELECT sku from ( # 上面的SQL ) AS tmp GROUP BY sku;
相关文章推荐
- Magento 查询产品SKU和价格的SQL
- Magento查询所有产品的Group Price, 返回 SKU和 价格
- [Magento SQL] 查询上架产品的近期销量统计
- Magento常用SQL:按产品Visibility过滤,查询所有产品
- sql的方式修改产品属性 - 避免使用event (magento)
- Magento返回产品name,sku,Description,ShortDescription,Specifications,Weight 的 SQL查询语句
- Magento SQL导出客户购物车产品信息(客户email,产品ID,产品名称,产品描述,产品价格,产品图片)
- Magento联表查询产品的Group Price 以及 历史已完成订单的产品的price 的 SQL 语句
- Oracle SQL Developer 连接数据库如何对应数据库配置文件
- PL/SQL 取几段查询结果的交集, 查询费用报表的条件(R12.1.1)所对应的费用报表规则
- C#开发ArcGIS Engine根据坐标提取对应区的属性(点选查询)
- 一个产品多个属性的查询总结
- mybatis-config.xml配置文件及sql分页查询的实现
- magento 获得自定义产品属性的属性值
- 批量修改zencart产品价格、原价、特价、产品属性价格
- zencart用sql将某个产品属性值设为只读和默认
- 多数据源,动态配置SQL实现灵活的查询
- Mybatis学习笔记(二)-----查询sql的配置文件
- magento如何获取产品属性值 How to Obtain Custom Attribute Values in Magento
- 【SQL语句】 - Ctrl+3 查询表属性的存储过程