MySQL高级查询语句
2018-01-11 17:54
701 查看
高级查询:
一:多表连接
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 外层表看油耗 里层求油耗的平均值(每一个数据都走一遍)
一:多表连接
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 外层表看油耗 里层求油耗的平均值(每一个数据都走一遍)
相关文章推荐
- MySql高级查询语句
- Mysql的字段类型,查询语句,高级操作
- MYSQL 语句高级应用之 多表查询及事务(二)
- Mysql高级查询语句练习
- MySQL高级查询语句
- 网上搜索到的 比较好的mysql查询语句练习题
- 处理mysql的查询语句去重案例一则
- MySQL 查询语句(1)
- php中mysql一条sql语句查询出所有符合条件的数据,该怎么写?
- Mysql DBA 高级运维学习笔记-DML语句之insert知识讲解
- MySQL学习小结:MySQL常用数据类型、常用MySQL查询语句
- 【MySQL】SELECT语句 联结表 高级联结 组合查询 全文本搜索
- 23个MySQL常用查询语句
- 浅谈MySQL中优化sql语句查询常用的30种方法
- 详解MySQL中的分组查询与连接查询语句
- mysql 常用查询语句记录
- mysql语句集锦(联表查询与时间戳转换)
- 23个MySQL常用查询语句
- 整理MySql常用查询语句(23种)
- mysql查询语句select-limit使用详解