mysql高级查询

高级查询:

1.连接查询

select * from Info,Nation #得出的结果称为笛卡尔积
select * from Info,Nation where Info.Nation = Nation.Code

join on连接

select * from Info join Nation #join连接
select * from Info join Nation on Info.Nation = Nation.Code


2.联合查询

select Code,Name from Info
union
select Code,Name from Nation


3.子查询

1)无关子查询

select Code from Nation where Name = '汉族' #去Nation表中查询汉族的民族代号

select * from Info where Nation = (民族代号) #在Info表中查询民族代号为上一个查询结果的所有信息

select * from Info where Nation = (select Code from Nation where Name = '汉族')

子查询查询的结果被父查询使用,子查询可以单独执行的成为无关子查询

 

2)相关子查询

select * from Car where Oil<(该系列的平均油耗) #查询油耗小于该系列平均油耗的

select avg(Oil) from Car where Brand = "值" #查询某系列的平均油耗

select * from Car a where Oil<(select avg(Oil) from Car b where b.Brand = a.Brand)

转载于:https://www.cnblogs.com/kevin2016/p/5425375.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值