DECLARE @ProductFeature TABLE (ProductID int, FeatureID int)
INSERT INTO @ProductFeature
SELECT 1,100
UNION ALL
SELECT 1,101
UNION ALL
SELECT 1,102
UNION ALL
SELECT 2,103
UNION ALL
SELECT 2,104
UNION ALL
SELECT 3,100
UNION ALL
SELECT 3,101
UNION ALL
SELECT 3,102
UNION ALL
SELECT 4,102
UNION ALL
SELECT 4,101
UNION ALL
SELECT 5,110
UNION ALL
SELECT 5,100
UNION ALL
SELECT 5,101
我的要求是,如果我通过ProductID = 1
了,那么我必须选择Product
具有类似于ProductID = 1
.
由于ProductID = 1
具有 3 个特征(100,101,102),因此只有ProductID = 3
具有相同计数的特征和具有ProductID = 1
预期结果
ProductID FeatureID
3 100
3 101
3 102