简体   繁体   中英

How to get the set of rows which are having same cut-off marks?

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

In above table Ram and Albert as well as Ganesh and John having same cut-off value. How can i get all these rows?

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`

for faster performance, add an INDEX on column Cut-off

Here is one way to do it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM