SQL Statement using Where clause with multiple values

前端 未结 3 731
盖世英雄少女心
盖世英雄少女心 2020-12-07 17:39

I have a table that has multiple rows with the following fields:

PersonName SongName Status

I want to use names selected from a multiple s

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 18:28

    Try this:

    select songName from t
    where personName in ('Ryan', 'Holly')
    group by songName
    having count(distinct personName) = 2
    

    The number in the having should match the amount of people. If you also need the Status to be Complete use this where clause instead of the previous one:

    where personName in ('Ryan', 'Holly') and status = 'Complete'
    

提交回复
热议问题