MySQL高级查询语句

MySQL高级查询语句

高级查询:
一:多表连接
1.select Info.Code,Info.Name,Nation.Name from Info,Nation where Info.Nation = Nation.Code 查几张表就就输出几张表,查那个条件就输出那个条件 列的查询
select * from Info,Nation 全部输出4x4

2.join连接
select * from Info join Nation on Info.Nation = Nation.Code 筛选输出数据

二:多表联合
select * from Info where Code='p001’union select * from Info where Nation=‘n001’ union 联合 行的查询

三:子查询(无关子查询)
select * from Info where Nation = (select Code from Nation where Name=‘汉族’) 两个查询 一个查询的结果当做另一个查询的条件 查一个 =
select * from Info where Nation in (select Code from Nation where Name=‘汉族’ or Name=‘苗族’)
in(在里面)not in (在不里面)任意一个都可以 作为两个查询结果的链接 查两个in

四:子查询(相关子查询)
select * from Car a where a.Oil <(select avg(Oil) from Car b where b.Brand = a.Brand)
把外子查询定义一个a 里面的表定义成b 外层表看油耗 里层求油耗的平均值(每一个数据都走一遍)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值