sql语句 子查询any exists left

--使用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

转载于:https://www.cnblogs.com/jone606/archive/2011/11/24/2261859.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值