╔════════╦═══════╗
║ ItemID ║ Value ║
╠════════╬═══════╣
║ 1 ║ A ║
║ 1 ║ C ║
║ 2 ║ A ║
║ 2 ║ D ║
║ 3 ║ A ║
║ 3 ║ C ║
╚════════╩═══════╝
我怎样才能获得物品数量 等于A和C的值
在这种情况下应该是2(第1项和第3项)
答案 0 :(得分:1)
Select Count(Item_Id) from TableName where Value='A' or Value='C'
group by Item_Id having Count(Item_Id)>1
答案 1 :(得分:1)
假设value
对于每个itemId
SELECT COUNT(*)
FROM
(
SELECT ItemID
FROM tableName
WHERE value IN ('A', 'C') -- the values you are looking
GROUP BY ItemID
HAVING COUNT(*) = 2 -- the number of values
) a