sqlserver left join的on中如何添加多个查询条件??

sweetBug sweetBug 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区


create table teacher
(
tid varchar(12) not null,
tname varchar(20) not null,
constraint PK_TEACHER primary key (tid)
)
go

create table student
(
xh varchar(20) not null,
tid varchar(12) null ,
sname varchar(20) not null,
constraint PK_STUDENT primary key (xh)
)
go


create index Relation_11_FK on student (tid)
go

alter table student
add constraint FK_STUDENT_RELATION__TEACHER foreign key (tid)
references teacher (tid)
go




如上,我有两个表,teacher和student.我想用left join查出一个老师下有多少个学生.
如:select teacher.* , student.* from teacher left join student on teacher.tid = student.tid;
但是我想再加上一个条件在后面,如是id为'0001'的老师所带的学生,应该怎么加?
我直接在后面加上..from teacher left join student on teacher.tid = student.tid and teacher.tid = '001'没有任何效果, 它还是会将所有老师的全查出来??
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
sweetBug
MS-SQL Server 34,876 成员 254,635 内容