0

我有一个包含以下字段的表:

 id | domainname | domain_certificate_no | keyvalue

select 语句的输出示例如下:

 id    |  domainname               |  domain_certificate_no      |  keyvalue
 ===============================================================================
'57092', '02a1fae.netsolstores.com', '02a1fae.netsolstores.com_1', '55525772666'
'57093', '02a1fae.netsolstores.com', '02a1fae.netsolstores.com_2', '22225554186'
'57094', '02a1fae.netsolstores.com', '02a1fae.netsolstores.com_3', '22444356259'
'97168', '02aa6aa.netsolstores.com', '02aa6aa.netsolstores.com_1', '55525772666'
'97169', '02aa6aa.netsolstores.com', '02aa6aa.netsolstores.com_2', '22225554186'
'97170', '02aa6aa.netsolstores.com', '02aa6aa.netsolstores.com_3', '22444356259’

该领域domain_certificate_no是独一无二的。我曾经group by找到重复的keyvalue,但我真正需要的不仅是出现了多少次,keyvalue而且我需要将重复的值与每个记录中的其他字段一一列出该值出现。我无法做到的事情group by。我怎样才能做到这一点。

4

3 回答 3

1

其他人的答案的另一种选择是INNER JOIN来自派生查询。

SELECT  a.*
FROM    myTable a
            INNER JOIN
            (
                SELECT keyValue
                FROM myTable
                GROUP BY keyValue
                HAVING COUNT(keyValue) > 1
            ) b 
                ON a.keyValue = b.keyValue
于 2012-08-08T02:56:32.480 回答
1

未经测试,但我认为这会在我的脑海中起作用

SELECT * FROM table 
    WHERE keyvalue IN (
      SELECT keyvalue FROM table GROUP BY keyvalue HAVING COUNT(*) > 1
    )
于 2012-08-08T01:57:30.070 回答
0

没有测试代码,但它应该可以帮助你更多;)

select group_concat(id) as all_id, group_concat(domainname) as all_domains, group_concat(domain_certificate_no) as all_certificats , keyvalue, count(keyvalue) from table x
group by keyvalue
order by count(keyvalue)
于 2012-08-08T02:00:07.403 回答