0
Name      Age      Cut-off
--------------------------
Ram       22        89.50
Ganesh    22        66.00
Sam       22        92.00
Albert    22        89.50
Kannan    22        65.45   
John      22        66.00

在上表中,Ram 和 Albert 以及 Ganesh 和 John 具有相同的截止值。我怎样才能得到所有这些行?

4

2 回答 2

2
SELECT  a.*
FROM    tableName a
        INNER JOIN
        (
            SELECT `Cut-off`, COUNT(*) totalCOunt
            FROM    tableName
            GROUP   BY `Cut-off`
            HAVING  COUNT(*) > 1
        ) b ON a.`Cut-off` = b.`Cut-off`

为了获得更快的性能,请添加一个INDEXon 列Cut-off

于 2013-02-05T14:58:33.137 回答
1

这是一种方法:

select *
from t
where exists (select 1 from t t2 where t2.cutoff = t.cutoff and t2.name <> t.name)
于 2013-02-05T15:06:44.147 回答