如何获得具有相同截止标记的行集?

时间:2013-02-05 14:56:51

标签: mysql sql

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具有相同的截止值。怎么能   我得到所有这些行?

2 个答案:

答案 0 :(得分: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`

要获得更快的效果,请在列INDEX

上添加Cut-off

答案 1 :(得分:1)

这是一种方法:

select *
from t
where exists (select 1 from t t2 where t2.cutoff = t.cutoff and t2.name <> t.name)