数据库查询
2016-03-13 15:49
197 查看
普通查询分:
普通查询(select 列,列 from 表名)
条件查询(where 列), 单条件_并列条件_或条件
模糊查询(where 列 like'内容%'),
统计查询(count(主键)/max(列)/min(列)/avg(列)/sum(列)), 各组之间用逗号隔开
排序查询(order by 列 desc),
分组查询(group by 列),
分页查询(limit (n-1)*x , x)
高级查询分:查询多个表
连接查询 (对列的扩展 / 相同的列要加表名,不同的列不用加表名)
形式1: select*from 表1,表2 where 表1.列0 = 表2.列0
形式2: select*from 表1 join 表2 on 表1.列0 = 表2.列0
联合查询(对行的扩展)
select*from info where nation = 'n001' union select*from info where code = 'p003'
无关子查询( 外查询不引导内查询 )
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 不用=
相关子查询 ( 外查询引导内查询 )
select*from car b where b.oil<(select avg(a.oil) from car a where a.brand = b.brand) //查询同一系列的油耗比平均油耗低的汽车信息,
普通查询(select 列,列 from 表名)
条件查询(where 列), 单条件_并列条件_或条件
模糊查询(where 列 like'内容%'),
统计查询(count(主键)/max(列)/min(列)/avg(列)/sum(列)), 各组之间用逗号隔开
排序查询(order by 列 desc),
分组查询(group by 列),
分页查询(limit (n-1)*x , x)
高级查询分:查询多个表
连接查询 (对列的扩展 / 相同的列要加表名,不同的列不用加表名)
形式1: select*from 表1,表2 where 表1.列0 = 表2.列0
形式2: select*from 表1 join 表2 on 表1.列0 = 表2.列0
联合查询(对行的扩展)
select*from info where nation = 'n001' union select*from info where code = 'p003'
无关子查询( 外查询不引导内查询 )
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 不用=
相关子查询 ( 外查询引导内查询 )
select*from car b where b.oil<(select avg(a.oil) from car a where a.brand = b.brand) //查询同一系列的油耗比平均油耗低的汽车信息,
相关文章推荐
- 简单mysql连接池
- MySQL基础知识总结
- JAVA操作Redis增删改查
- RedHat6.5 安装Oracle 12c RAC
- [置顶] oracle存储过程
- 看MySql如何实现批量操作
- MySQL Hash索引和B-Tree索引的区别
- mongodb3.2集群认证登陆
- oracle并非所有变量都已绑定
- 再谈Mysql中limit后的注入
- HBase Snapshot解析
- MySQL双主热备问题处理
- redis server
- SQLite Pragma语法
- 使用Loadrunner11录制MySQL协议脚本
- redis 事务
- redis事务中的WATCH命令和基于CAS的乐观锁
- redis WATCH命令介绍
- 学习数据库之MySql数据库
- MySQL数据库总结(11)索引