SQLServer —— EXISTS子查询

一、删除数据库

use master
go
if exists (select * from sysdatabases where name = 'Demo')
drop database Demo
go

二、删除表

use PhoneList
go
if exists (select * from sysobjects where name = 'PCategory')
drop table PCategory
go

三、子查询

有如下一张学员成绩表:

现在,有这么个需求,查询 C# 考试成绩,如果存在不及格的学员,则显示本次考试较难,否则显示本次考试内容适中,解决方案如下:

(1)、使用 exists

(2)、使用 not exists

猜你喜欢

转载自www.cnblogs.com/xulinjun/p/12032116.html