oracle10g sql查询基础笔记
来源:互联网 发布:网络小电视浴室电视机 编辑:程序博客网 时间:2024/05/07 04:45
1.常识基础
聚集函数不能出现在WHERE条件里面。
分组的时候group by 后面出现的字段可以不在SELECT后面出现,但select里面出现的表字段必须在group by后面出现。
一般使用聚集函数一定要想到用having,聚集函数一般是配合having来使用的。having要出现在group by之后。
2.模糊查询
select * from aa where a1 like 'a%'; 以a开头任意个字符结尾的。'a_'以a开头一个任意字符结尾的,如果有多个可以用多个'a__'。
select * from aa where a1 like '%a%';只要a1字段包含了a的都查询出来。
3.表连接
内连接
外连接:左外连接、右外连接。
4.子查询
无关子查询:in关键字 -->select * from e where id in (select id from d);
exists关键字-> select * from e where exists (select id from d);判断子句select id from d;中是否有结果集,如果有数据则e中数据全部显示出来,否则不
显示。
相关子查询:in关键字->select * from e where id in (select id from d where id=e.id and id='03');
not in用法--> 取反:select * from e where id not in (select id from d where id=e.id and id='03');
子查询的语句中不能有*。
注意:exists字句中可以有*符号。
exists用法-> select * from e where exists (select id from d where id=e.id);
not exists用法->select * from e where not exists (select id from d where id=e.id);
union用法-->表之间合并行数据,只是在显示一起没有物理的合并在一起:select eid,ename from e union select id,name from d;
注意:它会去掉重复的数据。
intersect用法-->显示出两个表都匹配的数据行:selelct id from e intersect select id from d;
批量插入数据方法:insert into e (eid,ename) select id,name from d;
创建表参考别的表并且把数据拷贝过来,也可以用*指定字段也可以带条件:create table ttt as (select * from e);
- oracle10g sql查询基础笔记
- Oracle10G学习笔记之四Pl/sql基础
- Oracle10G学习笔记之二Sql*plus基础、实例的启动与关闭
- oracle10g 基础以及SQL函数使用方法
- oracle10G学习笔记(SQL开发指南)
- oracle10G学习笔记(SQL开发指南)续
- Oracle10G学习笔记之三Sql
- oracle10g 学习笔记---sql*plus常用命令1
- oracle10g基础
- Oracle10g SQL分页查询写法与效率比较
- oracle10g中的wm_concat 实现sql查询结果多行转一行
- SQL查询语句基础
- 基础查询sql
- SQL查询(一)基础
- SQL 基础-->SELECT 查询
- SQL 基础--> 子查询
- T-SQL查询基础
- sql 基础查询操作
- android UI进阶之style和theme的使用
- 802.11 学习笔记
- 学习笔记 --内省
- 比较重要的三个正则表达式(JAVA)
- 【转】WTL-Open file dialog of new vista/win7 style
- oracle10g sql查询基础笔记
- 动态加载DLL的测试
- 使用仿函实现函数参数的部分自动填充
- 男人操蛋的一辈子
- 没事自己写的一个纳秒级计时器
- C语言之——strlen()与sizeof()
- 学习笔记 --XML
- 解读 nginx 中 chain 和 buf
- Some understanding about the MVC