一题目,求多方法
create table T( id int,name varchar(4))insert into T values(1,'A'),(1,'B'),(2,'A'),(2,'C'),(3,'C');--选出name有A无B的id号--方法一:select * from (select * from T where name='A')as a where ID<>(select id from T where name='B')
create table T( id int,name varchar(4))insert into T values(1,'A'),(1,'B'),(2,'A'),(2,'C'),(3,'C');select t1.*from T t1where t1.name='A' and not exists(select 1 from T t2 where t2.id=t1.id and t2.name='B')/*id name----------- ----2 A(1 row(s) affected)*/
[解决办法]
SELECT *FROM t AS aWHERE NAME = 'a' AND NOT EXISTS ( SELECT 1 FROM t WHERE id = a.id AND NAME = 'b' )