如何根据值选择仅记录组?

时间:2015-12-22 21:47:55

标签: sql sql-server tsql

如何仅选择匹配= 1的匹配MDM组?所以我从:

开始
            Score   MDM
            0       1001961
            0       1001961
            0       1001961
            0       1100406
            1       1100794
            0       1100794
            1       1101109
            0       1101109

但我最终应该:

            Score   MDM
            1       1100794
            0       1100794
            1       1101109
            0       1101109

1 个答案:

答案 0 :(得分:1)

一种选择是使用exists

select score, mdm
from yourtable t
where exists (
    select 1
    from yourtable t2
    where t.mdm = t2.mdm and t2.score = 1
)