我正在尝试查找表中的所有重复项并更改其中一个值。 现在我使用:
SELECT Amount
FROM Bids
GROUP BY Amount, AuctionID
HAVING ( COUNT(Amount) > 1 ) AND (AuctionID=1)
仅返回
的问题Amount
23.6500
41.8800
42.3500
而不是
Amount
23.6500
23.6500
41.8800
41.8800
42.3500
42.3500
所以我无法更新所有行。
我怎样才能按照我展示的方式获得它?
谢谢, 丹
答案 0 :(得分:3)
将其包装在IN查询中:
SELECT Amount
FROM Bids
WHERE Amount IN (
SELECT Amount
FROM Bids
GROUP BY Amount, AuctionID
HAVING ( COUNT(Amount) > 1 ) AND (AuctionID=1)
)
更新:添加了UPDATE语句
UPDATE Bids
SET Burned = 1
WHERE Amount IN (
SELECT Amount
FROM Bids
GROUP BY Amount, AuctionID
HAVING ( COUNT(Amount) > 1 ) AND (AuctionID=1)
)
答案 1 :(得分:0)
假设您在出价表中有Id:
SELECT Amount
FROM Bids b1
WHERE AcutionId = 1
AND EXISTS (Select 1 from Bids b2
WHERE b2.AuctionID = b1.AuctionId
AND b1.Amount = b2.Amount
AND b1.Id <> b2.Id)
答案 2 :(得分:0)
我很想知道为什么你的原始选择不满足你的要求。如果对于一组重复项中的每个成员,您只选择其中一个,那么您需要更新一个。将AuctionId添加到Frank Schmitt提供的选择中以查看区分这些行的信息应该是有用的。