日期:2014-05-17 浏览次数:20450 次
if object_id('student') is not null
drop table student
go
create table student
(
id int,
name nvarchar(20)
)
go
if object_id('attendence') is not null
drop table attendence
go
create table attendence
(
id int,
date datetime
)
go
insert into student
select 1,'张三' union all
select 2,'李四' union all
select 3,'王五' union all
select 4,'赵六'
go
insert into attendence
select 1,'2013-5-26' union all
select 1,'2013-5-27' union all
select 2,'2013-5-26' union all
select 1,'2013-5-28'
go
select * from student
where id not in (select id from attendence group by id having count(*)>=3)
select *
from student a
where not exists
(select count(1)
from attendence b
where a.id = b.id
group by b.id
having count(1)>=3)