22,207
社区成员
发帖
与我相关
我的任务
分享
--not 为非的意思,考虑不要not 的情况
select * from school.dbo.Student
where (name!='李四' or id='2006003'
--得出的结果应该为
2006001 张三 123456789
2006003 陈璐 1234567892
2006004 吴号 1234567893
2006005 叶高 1234567894
--除记录李四未出来,其它记录都出来,加上not 当然就变成只有李四出来,其它记录都不出来
select * from school.dbo.Student
where (name!='赵璐' and id='2006003')
--name!='赵璐'得出所有记录
2006001 张三 123456789
2006002 李四 1234567891
2006003 陈璐 1234567892
2006004 吴号 1234567893
2006005 叶高 1234567894
--加上id='2006003'就得出 陈璐一条记录
2006003 陈璐 1234567892
--加上not 就变为除陈璐外的其它记录
2006001 张三 123456789
2006002 李四 1234567891
2006004 吴号 1234567893
2006005 叶高 1234567894
use [csdn]
go
create table student(id nvarchar(10),cname nvarchar(20),phone nvarchar(20))
go
insert into student values('2006001','张三','123456789')
insert into student values('2006002','李四','1234567891')
insert into student values('2006003','陈璐','1234567892')
insert into student values('2006004','吴号','1234567893')
insert into student values('2006005','叶高','1234567894')
go
select * from student where not ( cname!='李四' or id='2006003')
--相当于
select * from student where cname ='李四' and id !='2006003'
/*
id cname phone
---------- -------------------- --------------------
2006002 李四 1234567891
(1 row(s) affected)
*/
go
select * from student where not (cname!='陈璐' and id='2006003')
--相当于
select * from student where cname ='陈璐' or id !='2006003'
/*
id cname phone
---------- -------------------- --------------------
2006001 张三 123456789
2006002 李四 1234567891
2006003 陈璐 1234567892
2006004 吴号 1234567893
2006005 叶高 1234567894
(5 row(s) affected)
*/