create table test
(
id int,
[name] varchar(20)
)
insert into test values(2,'aa');
insert into test values(2,'dd');
insert into test values(3,'bb');
insert into test values(4,'cc');请问怎么写啊,最好能用exists写出来?
(
id int,
[name] varchar(20)
)
insert into test values(2,'aa');
insert into test values(2,'dd');
insert into test values(3,'bb');
insert into test values(4,'cc');请问怎么写啊,最好能用exists写出来?
关键词 distinct 用于返回唯一不同的值。
这样可以过滤掉id相同的结果
select x.id, x.name from (select id,name,count(1) count from test group by id,name) x where x.count=1
select id,name,count(1) count from test group by id,name having count=1;
用exists查询语句替换