查出在B列有指定值的A列值

create table test (NAME varchar(20) not null, HOBBY varchar(20) not null);    

     insert into test values('Adam','basketball');  

     insert into test values('Bill','basketball');  

     insert into test values('Bill','football');  

     insert into test values('Cyper','basketball');  

     insert into test values('Cyper','badminton');  

     insert into test values('David','basketball');  

     insert into test values('David','badminton');  

     insert into test values('David','table tennis');  

使用SQL语句查出哪些人即会玩basketball又会玩badminton,找出这样的name-hobby组合。

SELECT NAME  ,HOBBY

        FROM TEST  

        WHERE HOBBY IN ('basketball', 'badminton')  

        GROUP BY NAME  

        HAVING COUNT(NAME) = 2

 

原文地址:http://www.iteye.com/topic/1122917



你可能感兴趣的:(a)