0

这是我的桌子。

ProductID 标题 UPC 显示
43 Motobecane Fantom 2634 0
14 重力 FSX 3301 1
19 重力 FSX 1.0 3301 1
56 芒果金刚鹦鹉 2834 1

我想选择具有重复 UPC 的行,其中 Display=1。这是我的代码不起作用:

Select ProductID, Title, UPC, Display from Products
Where Display=1
group by UPC having count(*) > 1;
4

1 回答 1

3

此解决方案假定 SQL Server:

SELECT    ProductID,
          Title,
          UPC,
          Display
FROM      Products
WHERE     UPC IN(
                     SELECT   UPC
                     FROM     Products
                     WHERE    DISPLAY = 1
                     GROUP BY UPC
                     HAVING   COUNT(UPC) > 1
                )
AND       Display = 1
于 2012-04-30T17:39:11.400 回答