0

这是我的桌子

显示          UPC
0 0553406259120
0 0753406259120
1 0753406259120
1 0453406259120

如果您注意到,第 2 行和第 3 行具有相同的 UPC。我想删除所有显示 = 0 并重复 upc 的行。所以在我的表中,我只想删除第 2 行。到目前为止,这是我的coldfusion代码不起作用。请指教。

<cfquery name="GetData" datasource="#Application.ds#" dbtype="ODBC" username="#Application.UserName#" password="#Application.Password#">
DELETE UPC
FROM products
WHERE DISPLAY = 0
GROUP BY UPC  
HAVING COUNT(*)>1
</cfquery>
4

2 回答 2

3

假设您要删除所有UPC相同但Display不同的行:

DELETE FROM Products as a
WHERE display = 0
AND EXISTS (SELECT '1'
            FROM Products as b
            WHERE b.display <> 0
            AND b.upc = a.upc)

这应该适用于所有 RDBMS,并将删除所有UPC相同但Display代码不同的行。

于 2012-04-23T22:22:23.537 回答
0
DELETE FROM Products
WHERE DISPLAY = 0 
AND UPC in (SELECT UPC
            FROM Products
            GROUP BY UPC
            HAVING COUNT(UPC)>1)
于 2012-04-23T22:36:15.317 回答