简单描述一下吧
原始数据如下if object_id('tempdb.dbo.#teacher') is not null drop table #teacher
create table #teacher (id int,name varchar(4))
insert into #teacher
select 1,'张三' union all
select 2,'李四' union all
select 3,'王五'
goif object_id('tempdb.dbo.#teacher') is not null drop table #teacher
create table #teacher (id int, varchar(10),mouth int)
insert into #teacher
select 1,'完成',1 union all
select 1,'完成',2 union all
select 2,'完成',1 union all
select 2,'未完成',2 union all
select 3,'完成',1 union all
select 3,'王五',2
go
简单来说,就是检索说1,2月老师考核 都是完成名单(只要有一个月考核没完成,就是不合格,所以2号老师就是不合格)检索的结果如下 teacherid teachername
1 张三 合格
3 王五 合格 因为【教师表】 对 【教师考核表】是1对多的关系,inner join不行的
小弟,考虑到 用游标做,不过不知道如何把 筛选出来的结果放到一个数据集中。
如各位有更好的方法,也不妨分享一下
原始数据如下if object_id('tempdb.dbo.#teacher') is not null drop table #teacher
create table #teacher (id int,name varchar(4))
insert into #teacher
select 1,'张三' union all
select 2,'李四' union all
select 3,'王五'
goif object_id('tempdb.dbo.#teacher') is not null drop table #teacher
create table #teacher (id int, varchar(10),mouth int)
insert into #teacher
select 1,'完成',1 union all
select 1,'完成',2 union all
select 2,'完成',1 union all
select 2,'未完成',2 union all
select 3,'完成',1 union all
select 3,'王五',2
go
简单来说,就是检索说1,2月老师考核 都是完成名单(只要有一个月考核没完成,就是不合格,所以2号老师就是不合格)检索的结果如下 teacherid teachername
1 张三 合格
3 王五 合格 因为【教师表】 对 【教师考核表】是1对多的关系,inner join不行的
小弟,考虑到 用游标做,不过不知道如何把 筛选出来的结果放到一个数据集中。
如各位有更好的方法,也不妨分享一下
drop table #teacher
create table #teacher (id int,name varchar(4))
insert into #teacher
select 1,'张三' union all
select 2,'李四' union all
select 3,'王五'
go
if object_id('tempdb.dbo.#teacher') is not null
drop table #teacher
create table #teacher (id int, varchar(10),mouth int)
insert into #teacher
select 1,'完成',1 union all
select 1,'完成',2 union all
select 2,'完成',1 union all
select 2,'未完成',2 union all
select 3,'完成',1 union all
select 3,'王五',2
goSelect
teacherid=id,
teachername=name,
='合格'
From #teacher a
Where Not Exists(Select 1 From #teacher Where id=a.id And ='未完成')/*
teacherid teachername
1 张三 合格
3 王五 合格
*/
teacherid=id,
teachername=name,
='合格'
From #teacher a
Where Not Exists(Select 1 From #teacher Where mouth In(1,2) And id=a.id And ='未完成')--Or
Select
teacherid=id,
teachername=name,
='合格'
From #teacher a
Where id Not In(Select Distinct id From #teacher Where mouth In(1,2) And ='未完成')