-1

我有下表代表产品及其属性/属性。我需要编写一个查询来获取为产品value命名的属性。Insert StyleFirst Choice MaterialGold

在此处输入图像描述

我做到了这一点:

SELECT * 
FROM shop_product_properties
WHERE name = 'Insert Size'
AND product_id IN (
    SELECT DISTINCT product_id
    FROM shop_product_properties
    WHERE ((LOWER(name) = 'first choice material'
    AND value = 'Aluminium') AND (LOWER(name) = 'insert style' AND value = 'CCGT'))
);
4

1 回答 1

1

我需要编写一个查询,该查询将获取名称为 Insert Style 的所有值

所以从那开始:

SELECT * 
FROM shop_product_properties
WHERE name = 'Insert Style';

其中 First Choice Material = Gold 并且它们具有相同的 product_id

然后引入一个子查询:

SELECT * 
FROM shop_product_properties
WHERE name = 'Insert Style'
AND product_id IN (
    SELECT DISTINCT product_id
    FROM shop_product_properties
    WHERE name = 'First Choice Material'
    AND value = 'Gold'
);

http://sqlfiddle.com/#!2/ecfb4/1

于 2013-09-19T21:11:30.643 回答