(三)java数据库篇笔记库(34)
来源:互联网 发布:list获取指定元素java 编辑:程序博客网 时间:2024/06/07 13:35
一. 必背的sql语句
1 ) . oracle分页
select * from(select.*,rownum rn from(select *from menu order by id desc)t where rownum<10)where rn >=5
2 ) . mysql 分页
select * from music where id limit 5,5
3 ) . oracle如何快速将一张表的数据复制到另外一张表中(另外一张表不存在,另外一张表存在,但数据为空)
3.1,不存在另一张表时 : create table 新表名 as select * from 将要复制的表名3.2.存在另一张表时 : insert into 新表名 select 字段 from 将要复制的表名
4 ) . 音乐专辑 : 查询出special<app:ds:special>表中的id ,专辑名,以及下边有多少歌曲select s.di,min(s.sname),count(m.mid) from special s inner join ms m on s.id=m.id group by s.id5 ) . 快速删除一张表(不可事务回滚,也就是没有日志记录)TRUNCATE from 表名6 ) . inner join (合并)select 查询信息 from 表名 1 innerjoin 表名 2 on 表名 1.列名=表名 2.列名7 ) . left join(左外连接)select 查找信息 from 表名 1 left join 表名2 on 表名1.列名 =表名2.列名8 ) . right join(右外连接)select 查找信息 from 表名 1 right join 表名2 on 表名1.列名 =表名2.列名9 ) . oracl中查询遍历树形结构(start with) : select * ftom extmenu start with pid =1 connect by prior id=pid快速删除父节点以及父节点下的所有节点 : Delete from extmenu where id in ( select * from extmenu start with pid=1 connect by prior id=pid)10 ) . 查询出来60-70,80-90,95-100学生的信息
方式一 : select * from stu where chengji between 60 and 70 or between 80 and 90 or between 95 and 100方式二: select * from stu where chengji<60 and chengji<70 or chengji>80 and chengji<90 or chengji>95 and chengji <100
11 ) . 用exists替换in----进行联表查询
方式一 : select * from dept where exists (select * from emp where emp.deptno=dept.deptno)方式二 : select * from dept d inner join emp e on d.deptno =e.deptno(只查询出两表共同拥有的字段数据)
12 ) . 删除表表中的重复数据 :delete from xin a where a.rowid != {select max(b.rowid) from xin b where a.name=b.name};
13 ) . row_number() ,rank( ) over, dense_rank() over 按工资排序
select sal,
row_number() over(order by sal desc) rank1 ,tank() over (oder by sal desc ) rank,dense_rank() over (order by sal desc)drank
from emp
14 ) . select * from ( select emp.* from ( dense_rank over ( partition by departNo order by sal desc ) rk from emp)where rk=4
二. ibatis批量
1 ) .this.getSqlMapClientTemplate().execute(new SqlMapClientCallback(){public Object doInSqlMapClient(SqlMapExecutor executor )throws SQLException{executor.startBatch();for(int i=0,n=list.size();i<n;i++){executor.insert("productAttach.insertProductAttach",list.get(i));}executor.executeBatch();return null;}});ibatis.jdbc.hibernate的分段的实现 :都应该在组装list的时候进行拆分(如:action 层加入)if(list.size()%1000==0){productAttachService.addBatch(list);list.clear();}if(list.size()>0)productAttachService.addBatch(list);
阅读全文
0 0
- (三)java数据库篇笔记库(34)
- (三)java数据库篇笔记库(29)
- (三)java数据库篇笔记库(30)
- (三)java数据库篇笔记库(31)
- (三)java数据库篇笔记库(32)
- (三)java数据库篇笔记库(33)
- (三)java数据库篇笔记库(35)
- JAVA笔记:Java数据库编程(三)
- 数据库笔记三
- 数据库笔记(三)
- 学习数据库笔记三
- (三)java业务场景篇笔记库(36)
- (三)java业务场景篇笔记库(37)
- (三)java业务场景篇笔记库(38)
- 数据库学习笔记(三)
- 数据库学习笔记(三)
- 数据库学习笔记(三)
- 数据库学习笔记(三)
- composer 手动安装及简单使用 windows
- 关于 shiro 学习第一天
- 十二周-编写一个JFrame窗口
- NoClassDefFoundError 和 ClassNotFoundException的区别
- Java并发编程-并发编程知识点总结
- (三)java数据库篇笔记库(34)
- 【健身增肌方法】
- c++学习系列:stringstream的用法
- BottomNavigationView的特殊用法
- 职场风云切记
- 国际消息:美国税改闹乌龙,黄金走势不稳定!
- vbs之使用语法
- Redis数据结构-String
- numpy计算两二维数组距离