(三)java数据库篇笔记库(34)
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
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);
(三)java数据库篇笔记库(34)相关推荐
- Java数据库篇8——索引、视图、存储过程、触发器
Java数据库篇8--索引.视图.存储过程.触发器 1.索引 1.1.索引是什么 在数据库表中,对字段建立索引可以大大提高查询速度.通过善用这些索引,可以令MySQL的查询和 运行更加高效 如果合理的 ...
- Java数据库篇7——数据库设计
Java数据库篇7--数据库设计 1.第一范式 列不可再分 每一列属性都是不可再分的属性值,确保每一列的原子性 两列的属性相近或相似或一样,尽量合并属性一样的列,确保不产生冗余数据 2.第二范式 属性 ...
- Java数据库篇9——备份与还原、忘记密码
Java数据库篇9--备份与还原.忘记密码 1.备份 备份的应用场景 在服务器进行数据传输.数据存储和数据交换,就有可能产生数据故障.比如发生 意外停机或存储介质损坏. 这时,如果没有采取数据备份和数 ...
- Java数据库篇6——多表查询
Java数据库篇6--多表查询 1.笛卡尔积 交叉连接查询 设集合A={a, b},集合B={0, 1, 2},则两个集合的笛卡尔积为{(a, 0), (a, 1), (a, 2), (b, 0), ...
- Java数据库篇5——事务
Java数据库篇5--事务 1.什么是事务 事务是一个整体,由一条或者多条SQL 语句组成,这些SQL语句要么都执行成功,要么都执行失败, 只要有 一条SQL出现异常,整个操作就会回滚,整个业务执行失 ...
- Java数据库篇4——表的约束
Java数据库篇4--表的约束 1.非空约束 字段不允许为空 #创建表的时候添加 Create table 表名(列1 数据类型 not null,列2 数据类型,列3 数据类型 ); #创建表以后添 ...
- Java数据库篇3——SQL
Java数据库篇3--SQL 结构化查询语言(Structured Query Language)简称SQL,是一种特殊目的的编程语言,是一种数据库 查询和程序设计语言,用于存取数据以及查询.更新和管 ...
- Java数据库篇2——数据库基本操作
Java数据库篇2--数据库基本操作 1.启动.停止.服务 net start mysql net stop mysql 2.登入登出 本地 Mysql -u用户名 -p密码Mysql -u用户名 - ...
- Java数据库篇1——数据库配置
Java数据库篇1--数据库配置 1.数据库 数据库(DataBase) 就是存储和管理数据的仓库 本质是一个文件系统, 还是以文件的方式,将数据保存在电脑上 2.数据库的优点 存储方式 优点 缺点 ...
最新文章
- Cisco路由器安全配置必用10条命令
- 朴素贝叶斯算法应用实例
- Keep the Customer Satisfied
- fileinput模块可以循环一个或多个文本文件的内容
- 算法竞赛训练指南代码仓库_数据仓库综合指南
- 一道有意思的导论问题
- NYOJ845 - 无主之地1
- Python中执行系统命令常见的几种方法
- c++拼接字符串效率比较(+=、append、stringstream、sprintf)
- 有约束最优化问题的相关讨论
- Lyn for Mac v2.1 中文版 – 轻量级图片浏览器
- 南通市城管局推动“数字化城管”向“智慧城管”升级
- Cortex-M3 (NXP LPC1788)之WDT窗口看门狗定时器
- HTML+CSS仿小米官网首页 项目总结
- 【Redis】数据结构的应用——GEO 【搜索“附近的餐馆”、在打车软件上叫车】
- 入门UVM验证方法学
- Tensorflow Win10 stage.2
- npcap 如何获得链路层类型
- 云栖回顾|龙蜥社区有哪些值得回味的精彩瞬间?
- 计算机以一级上级模拟试题,全国计算机等级考试一级模拟试题和答案
热门文章
- bnuoj 44359 快来买肉松饼
- 与计算机相关的英语句子,计算机英语的常用句子
- SpringBoot配置多数据源数据库
- 项目:chatroom_websocket、网页聊天室
- Python中的多行输入
- flash反编译杂记
- python识别图像中绿色的部分_[OpenCV-Python] OpenCV 中的图像处理 部分 IV (四)
- php跨平台审计工具,php源码审计工具–PHP Source Auditor 4 released
- 工具使用——使用华为手机作为电脑的拓展屏
- 2021年美容师(初级)考试及美容师(初级)考试资料