SQLServer--数据查询--子查询语法

——————————子查询—————————————-

———–将查询的结果作为子表,连表查询
select * from StuInfo s1,(select * from StuMarks where Score >80)s2 where s1.StuID=s2.StuID AND s1.StuName=’李四’

———–将查询结果作为条件使用
select * from StuInfo WHERE StuID>(select StuID from StuInfo where StuName=’王五’)
———–将子查询作为临时表使用
select s1.,s2 Score from StuInfo s1 left outer join (select from StuMarks where Subject=’HTML’) s2 on s1.StuID=s2.StuID
———–将子查询作为列使用 (不建议使用)
select s1.*,(select Score from StuMarks s2 where s1.StuID=s1.StuID and subject=’html’) Score from StuInfo s1
———–使用in 和not in 完成子查询
select StuName from StuInfo where StuID In (select StuID from StuMarks where Score >85 and Subject=’java’)
———–使用exist 或not exist 完成子查询
select * from StuInfo where exists (select * from StuMarks where StuMarks.StuID=StuInfo.StuID)
———–使用some 、any、 all进行子查询
——————–聚合函数—————————————————–
—————使用compute 和compute by进行汇总
———————-排序函数
—————排序函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值