如果存在重复的products_sku,我想获得与retailer_shop_id相关的重复product_sku,product_type值应该是“Variable”,否则它应该是“Simple”。
我认为伪代码查询将是这样的:
SELECT product_sku,
IF (current_product_sku_Count > 1, 'variable', 'simple') as product_type
FROM retailer_stock
where retailer_shop_id = "1";
如果我放入了什么条件?
答案 0 :(得分:0)
您可以计算子查询中每个产品的计数,然后在外部查询中按照您的方式执行if
:
SELECT product_sku,
IF(sku_count > 1 , 'variable', 'simple') as product_type
FROM
(
SELECT product_sku, COUNT(*) AS sku_count
FROM retailer_stock
where retailer_shop_id = "1";
GROUP BY product_sku
) AS t