时间:2010-07-26 17:28:59

标签: sql-server-2008

3 个答案:

答案 0 :(得分:1)

这将返回仅具有构面类型1和2的产品的行,并且仅返回那些构面。

SELECT ProductId,
    COUNT(*) AS FacetCountByProduct,
    SUM(CASE WHEN FacetTypeId in (1, 2) THEN 1 ELSE 0 END) AS FacetCountSelectedFacets
FROM ProductFacets
GROUP BY ProductId
HAVING COUNT(*) = 2
    and SUM(CASE WHEN FacetTypeId in (1, 2) THEN 1 ELSE 0 END) = 2
;

答案 1 :(得分:0)

答案 2 :(得分:0)

想到办法做到这一点:

select distinct ProductId from ProductFacets 
where ProductId in (select ProductId from ProductFacets where FacetTypeId = 1)
and ProductId in (select ProductId from ProductFacets where FacetTypeId = 2)