MySql高级查询语句
2017-02-27 12:34
656 查看
高级查询:
一:多表连接
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 查询语句分析explain
- 从一个MysqL的例子来学习查询语句
- LINQ to SQL语句之动态查询高级特性
- J2EE入门视频教程第五讲——MySQL中的数据类型及命令行基本查询语句
- JAVA连接MYSQL,查询 ,添加,删除,语句
- MYSQL导出查询结果语句,记录一下
- mysql的经典查询语句
- mysql查询替换语句
- mysql limit查询语句优化原则
- SQL server、MySQL、Oracle分页查询SQL语句
- 高级嵌套的查询sql语句
- sql高级语句查询
- MySQL中动态生成多条件查询语句
- 找出Mysql查询速度慢的SQL语句