--使用any
select * from class where cl_id>any(select cl_id from studio where st_age>30)
--使用all
select * from class where cl_id>all(select cl_id from studio where st_age>30)

 

 

--使用 exists ,该关键字引入一个子查询的时候基本上是对数据进行一次是否存在的测试
--我们查询那些人所在的班级是编号为 1 的
select * from studio where exists(select cl_id from class where studio.cl_id=class.cl_id and class.cl_id=1) 
--使用 not exists
select * from studio where not exists(select * from class where studio.cl_id=class.cl_id and class.cl_id=1) order by st_id

 

 

--从字符串的左边开始返回3个字符
select left(cl_class,3) from class
--同理,返回右边的
select right(cl_class,3) from class

 

--返回值的字符数
select len(cl_class) from class

--替换
select replace(cl_class,'实训','强化') from class

 

 

select host_id()
--返回工作站标识号

select host_name()
--返回工作站所运行的计算机名称


select db_id()
select db_name()
select object_id('Stu_course_ADD')
--通过名称得到这个服务器对象的服务器ID

select object_name(151671588)
--同上相反

 

 

--使用 having 子句 功能 - 指定组或者聚合的搜索条件,通常与group by 子句一起使用,完成分组查询后再进步筛选
select ho_id as '宿舍编号',avg(st_age) as '平均年龄' from studio group by ho_id   having avg(st_age)>35
--多条件
select ho_id as '宿舍编号',avg(st_age) as '平均年龄' from studio group by ho_id   having avg(st_age)>35 and ho_id>2