DB2表数据导出、导入及常用sql使用总结
export to [path(例:D:"TABLE1.ixf)]of ixf select [字段(例: * or col1,col2,col3)] from TABLE1;
export to [path(例:D:"TABLE1.del)]of del select [字段(例: * or col1,col2,col3)] from TABLE1;
export to d:\table1.txt of del select id, name, age, address, note fromtesttable order by id;
import from[path(例:D:"TABLE1.ixf)] of ixf insert into TABLE1;
load from [path(例:D:"TABLE1.ixf)]of ixf insert into TABLE1;
load from [path(例:D:"TABLE1.ixf)]of ixf replace into TABLE1; // 装入数据前,先删除已存在记录
load from [path(例:D:"TABLE1.ixf)]of ixf restart into TABLE1; // 当装入失败时,重新执行,并记录导出结果和错误信息
import from[path(例:D:"TABLE1.ixf)] of ixf savecount 1000 messages [path(例:D:"msg.txt)]insert into TABLE1;// 其中,savecount表示完成每1000条操作,记录一次.
存在自增长字段的数据导入:
load from [path(例:D:"TABLE1.ixf)]of ixf modified by identityignore insert into TABLE1;// 加入modified byidentityignore.
解除装入数据时,发生的检查挂起:
select emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),'日期不详')birthday from employee order by dept
2、查找与喻自强在同一个单位的员工姓名、性别、部门和职称 代码如下:
select emp_no,emp_name,dept,title from employee where emp_name<>'小明' and dept in (select dept from employee where emp_name='小明')
3、按部门进行汇总,统计每个部门的总工资 代码如下:
select dept,sum(salary) from employee group by dept
4、查找商品名称为14寸显示器商品的销售情况,显示该商品的编号、销售数量、单价和金额 代码如下:
selecta.prod_id,qty,unit_price,unit_price*qty totprice from sale_item a,product b where a.prod_id=b.prod_id and prod_name='14寸显示器'
5、在销售明细表中按产品编号进行汇总,统计每种产品的销售数量和金额 代码如下:
select prod_id,sum(qty) totqty,sum(qty*unit_price)totprice from sale_item group by prod_id
6、使用convert函数按客户编号统计每个客户1996年的订单总金额 代码如下:
select cust_id,sum(tot_amt) totprice from sales where convert(char(4),order_date,120)='1996' group by cust_id
7、查找有销售记录的客户编号、名称和订单总额 代码如下:
select a.cust_id,cust_name,sum(tot_amt)totprice from customer a,sales b where a.cust_id=b.cust_id group by a.cust_id,cust_name
8、查找在1997年中有销售记录的客户编号、名称和订单总额 代码如下:
select a.cust_id,cust_name,sum(tot_amt)totprice from customer a,sales b where a.cust_id=b.cust_id and convert(char(4),order_date,120)='1997' group by a.cust_id,cust_name
9、查找一次销售最大的销售记录 代码如下:
select order_no,cust_id,sale_id,tot_amt from sales where tot_amt= (select max(tot_amt) from sales)
select emp_name,order_date from employee a,sales b where emp_no=sale_id and a.emp_no in (select sale_id from sales group by sale_id having count(*)>=3) order by emp_name
select cust_name from customer a where not exists (select * from sales b where a.cust_id=b.cust_id)
selecta.cust_id,cust_name,convert(char(10),order_date,120),tot_amt from customer a left outer join sales b on a.cust_id=b.cust_id order by a.cust_id,tot_amt desc
select emp_name 姓名, 性别= casea.sex when 'm' then '男' when 'f' then '女' else '未' end, 销售日期= isnull(convert(char(10),c.order_date,120),'日期不详'), qty 数量, qty*unit_price as 金额 from employee a, sales b, sale_item c,product d where d.prod_name='16M DRAM' and d.prod_id=c.prod_id and a.emp_no=b.sale_id and b.order_no=c.order_no
14、查找每个人的销售记录,要求显示销售员的编号、姓名、性别、产品名称、数量、单价、金额和销售日期 代码如下:
select emp_no 编号,emp_name 姓名, 性别= casea.sex when 'm' then '男' when 'f' then '女' else '未' end, prod_name 产品名称,销售日期= isnull(convert(char(10),c.order_date,120),'日期不详'), qty 数量, qty*unit_price as 金额 from employee a left outer join sales b on a.emp_no=b.sale_id , sale_itemc,product d where d.prod_id=c.prod_id and b.order_no=c.order_no
15、查找销售金额最大的客户名称和总货款 代码如下:
select cust_name,d.cust_sum from customer a, (select cust_id,cust_sum from (select cust_id, sum(tot_amt) as cust_sum from sales group by cust_id ) b where b.cust_sum = ( select max(cust_sum) from (select cust_id, sum(tot_amt) as cust_sum from sales group by cust_id ) c ) ) d where a.cust_id=d.cust_id
select emp_no,emp_name,d.sale_sum from employee a, (select sale_id,sale_sum from (select sale_id, sum(tot_amt) as sale_sum from sales group by sale_id ) b where b.sale_sum <1000 ) d where a.emp_no=d.sale_id
17、查找至少销售了3种商品的客户编号、客户名称、商品编号、商品名称、数量和金额 代码如下:
selecta.cust_id,cust_name,b.prod_id,prod_name,d.qty,d.qty*d.unit_price from customer a, product b, sales c, sale_item d where a.cust_id=c.cust_id and d.prod_id=b.prod_id and c.order_no=d.order_no and a.cust_id in ( select cust_id from (select cust_id,count(distinct prod_id) prodid from (select cust_id,prod_id from sales e,sale_item f where e.order_no=f.order_no) g group by cust_id having count(distinct prod_id)>=3) h )
18、查找至少与世界技术开发公司销售相同的客户编号、名称和商品编号、商品名称、数量和金额 代码如下:
selecta.cust_id,cust_name,d.prod_id,prod_name,qty,qty*unit_price from customer a, product b, sales c, sale_item d where a.cust_id=c.cust_id and d.prod_id=b.prod_id and c.order_no=d.order_no and not exists (select f.* from customer x ,sales e, sale_item f where cust_name='世界技术开发公司' and x.cust_id=e.cust_id and e.order_no=f.order_no and not exists ( select g.* from sale_item g, sales h where g.prod_id = f.prod_id and g.order_no=h.order_no and h.cust_id=a.cust_id) )
19、查找表中所有姓刘的职工的工号,部门,薪水 代码如下:
select emp_no,emp_name,dept,salary from employee where emp_name like '刘%'
select cust_id from sales where tot_amt>2000
select count(*)as 人数 from employee where salary between 4000 and 6000
select avg(salary) avg_sal,dept from employee where addr like '上海市%' group by dept
update employee set addr like '北京市' where addr like '上海市'
select emp_no,emp_name,dept from employee where sex='F'and dept in ('业务','会计')
select prod_id ,sum(qty*unit_price) from sale_item group by prod_id order by sum(qty*unit_price) desc
select CUST_ID,cust_name,addr from customer where cust_id between 'C0001' AND 'C0004'
select count(distinct prod_id) as '共销售产品数' from sale_item
update employee set salary=salary*1.03 where dept='业务'
select * from employee where salary= (select min(salary ) from employee )
selecta.cust_id,b.tot_amt,b.order_date,a.tel_no from customer a join sales b on a.cust_id=b.cust_id and cust_name like '客户丙'
select * from sales where tot_amt>all (select tot_amt from sales where sale_id='E0013'and order_date='1996/10/15') order by tot_amt
select avg(unit_price) from sale_item where prod_id='P0001'
select sale_id,tot_amt from sales where sale_id in (select sale_id from employee where sex='F')
select a.emp_no,a.emp_name,a.date_hired from employee a join employee b on (a.emp_no!=b.emp_no and a.date_hired=b.date_hired) order by a.date_hired
select emp_no,emp_name from employee where emp_no in (select sale_id from sales group by sale_id having sum(tot_amt)<232000)
DB2表数据导出、导入及常用sql使用总结的更多相关文章
- Oracle数据导出导入(PL/SQL工具)
做了那么多年的开发第一次写博客,一开始是没想过要写博客的,后来想写,却一直不敢写,一个是怕自己写的不好,误导人家,二来是不太自信.现在想起写博客是因为,真正的勇士敢于面临淋漓的鲜血,希望能提高自己,也 ...
- db2表结构导出导入,数据库备份
1.新增用户组.用户和查看所有用户: 新增系统用户组: #groupadd jldb //增加用户组jldb 需使用root权限 useradd jldb -g jldb //将新增用户赋值到jldb ...
- 不同版本的SQL Server之间数据导出导入的方法及性能比较
原文:不同版本的SQL Server之间数据导出导入的方法及性能比较 工作中有段时间常常涉及到不同版本的数据库间导出导入数据的问题,索性整理一下,并简单比较下性能,有所遗漏的方法也欢迎讨论.补充. 0 ...
- sql server 应用bcp进行数据导出导入
bcp 实用工具可以在 Microsoft SQL Server 实例和用户指定格式的数据文件间大容量复制数据. 使用 bcp 实用工具可以将大量新行导入 SQL Server 表,或将表数据导出到数 ...
- Pl/sql 如何将oracle的表数据导出成excel文件?
oracle将表数据导出成excel文件的方法 1)在SQL窗体上,查询需要导出的数据 --查询数据条件-- ; 结果视图 2)在查询结果的空白处,右键选择Copy to Excel 3) 查看导出e ...
- SQL Server批量数据导出导入BCP&Bulk使用
数据导出导入,首先考虑使用什么技术实现导出与导入利用BCP结合Bulk技术实现数据的导出与导入 1.bcp数据导出(这里是命令行方式),导出的数据需是格式化的,有两种方式可选 a.对传输的数据格式要求 ...
- SQL2008全部数据导出导入两种方法【转】
方法一:生成脚本导出导入sql2008全部数据 第一步,右键要导出的数据库,任务--生成脚本 第二步,在设置脚本编写选项处,点击--高级(A),选择要编写脚本的数据的类型为:架构和数据 如果找 ...
- Oracle如何实现创建数据库、备份数据库及数据导出导入的一条龙操作
Oracle中对数据对象和数据的管理,无疑都是使用PL/SQL Developer来进行管理,该工具也提供给我们很多方便.快捷的操作,使得我们不再为Oracle本身丑陋.难用的UI而抱怨.由于我们一般 ...
- [转]Oracle如何实现创建数据库、备份数据库及数据导出导入的一条龙操作
本文转自:http://www.cnblogs.com/wuhuacong/archive/2012/03/09/2387680.html Oracle中对数据对象和数据的管理,无疑都是使用PL/SQ ...
随机推荐
- tensorflow源码解析之common_runtime-executor-上
目录 核心概念 executor.h Executor NewLocalExecutor ExecutorBarrier executor.cc structs GraphView ExecutorI ...
- tensorflow编译成功!
使用bazel编译tensorflow项目的core包成功!找了个简单的target可视化,留作纪念,命令如下: bazel query --noimplicit_deps --nohost_deps ...
- CentOS8时间同步
CentOS8中默认已经不再支持ntpd软件包,同时也无法通过官方软件仓库安装, CentOS8上使用Chrony配置NTP服务器,用于同步时间. 它有两个程序,chrony和chronyd, chr ...
- mysql 聚集索引和非聚集索引
聚集索引:聚集索引表示表中存储的数据按照索引的顺序存储,检索效率比非聚集索引高,但对数据更新影响较大: 非聚集索引:非聚集索引表示数据存储在一个地方,索引存储在另一个地方,索引带有指针指向数据的存储位 ...
- JavaWeb 07_创建web项目连接MySQL实现注册登录功能
一.创建一个web项目,参照JW/01_创建web项目及部署 二.在NAVICat 里建数据库 db_01,建表tb_user ,字段UName .Pwd 三.在web下创建一个Directory, ...
- NoSQL:Redis缓存、雪崩、击穿、穿透
Redis介绍 Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库 ...
- TetBrains产品快捷键大全
快捷键大全
- struts2学习二:Tomcat的部署目录和访问路径问题
1:idea中配置tomcat后,那么最终的web工程发布到哪里去了?为什么在访问路径中不加工程名就可以访问? 1.1:因为tomcat有段时间没接触了,先回顾下tomcat的目录结构吧? 如图所示: ...
- Oracle入门基础(一)一一基本查询
SQL> --当前用户 SQL> show user SQL> --当前用户下的表 SQL> select * from tab; TNAME TABTYPE CLUSTERI ...
- 什么是 Idempotence 以及它在哪里使用?
幂等性是能够以这样的方式做两次事情的特性,即最终结果将保持不变,即好像 它只做了一次. 用法:在远程服务或数据源中使用 Idempotence,这样当它多次接收指令时,它 只处理指令一次.