SQL 按大于 1 分组

SQL Group by Having > 1

也许标题不是我能用来描述问题的最佳标题 我正在处理的 table 结构的示例如下图所示。我需要编写一个查询来提取 "Manufactures" 的所有记录,这些记录有多个记录。所以最终结果我会 LINUX UBUNTU 5.6 和 LINUX REDHAT 7.8

只需返回重复的 MANUFACTURE 很容易,我可以使用计数 (*) > 1 的分组来做到这一点,但是当涉及到返回重复的制造及其相应的列时,我遇到了问题.

returning the duplicated MANUFACTURE is easy and I can do that with using grouping having count(*) > 1

这是一个好的开始。现在使用 manufacture 的列表到 select 其余数据:

SELECT *
FROM software
WHERE manufacture IN (
    -- This is your "HAVING COUNT(*) > 1" query inside.
    -- It drives the selection of rows in the outer query.
    SELECT manufacture
    FROM software
    GROUP BY manufacture
    HAVING COUNT(*) > 1
)

试试这个:

  Select * from myTable
  Where Manufacture In
      (Select Manufacture
       from myTable
       Group By Manufacture
       Having count(*) > 1)

你有没有尝试过类似的东西:

select p.manufacture, p.product, p.version
from (select manufacture, count(*)
    from products
    group by manufacture) as my_count
inner join products as p on p.manufacture = my_count.manufacture
where my_count > 1