0

我在尝试进行以下选择工作时遇到问题。任何人都可以帮忙吗?谢谢。

SELECT 
        i.InventoryID,i.AttributeSKUID,s.AttributeValue
    FROM 
        ma_product_inventory i
    LEFT JOIN
        ma_product_attribute_sku s
    ON
        i.AttributeSKUID=s.AttributeSKUID
    LEFT JOIN
        ma_product p
    ON
        p.ProductID=s.ProductID
    WHERE 
        s.ProductID='1'
    AND
        (
        s.AttributeValue='xs'
        OR
        s.AttributeValue='green'
        )

我得到以下结果:

INVENTORYID ATTRIBUTESKUID  ATTRIBUTEVALUE
1   1   xs
1   1   green
2   2   green
3   3   green
4   4   green
5   5   green
6   6   xs

我怎样才能获得 AttributeSKUID?

谢谢。

4

4 回答 4

2

在查询末尾添加此内容 GROUP BY s.AttributeValue

于 2013-04-24T08:40:19.457 回答
2

尝试使用SELECT DISTINCT,你为什么加入ma_product p?看来你没有使用那张桌子。

于 2013-04-24T08:46:45.417 回答
2

尝试通过具有 count (*) =2 的 S.attributeSKUID 在 kyusan93 代码Select distinct(s.attribute),i.inventoryId,s.attributevalue组添加不同的 - 这将使所有 attributeSKUID 重复两次。希望对您有所帮助。

于 2013-04-27T04:50:12.997 回答
0
Select s.AttributeSKUID 
from
ma_product_attribute_sku s
LEFT JOIN
ma_product p
ON
p.ProductID=s.ProductID
WHERE 
s.ProductID='1'
AND
(s.AttributeValue='xl'
OR
s.AttributeValue='red')
Group by 
S.AttributeSKUID
having count(*) = 2
于 2013-04-24T10:27:43.870 回答