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 ...
随机推荐
- Spring系列20:注解详解和Spring注解增强(基础内功)
有部分小伙伴反馈说前面基于注解的Spring中大量使用注解,由于对Java的注解不熟悉,有点难受.建议总结一篇的Java注解的基础知识,那么,它来了! 本文内容 什么是注解? 如何定义注解 如何使用注 ...
- [ Skill ] load 函数优化,识别相对路径
https://www.cnblogs.com/yeungchie/ 在 cds.lib 文件中定义库的路径,为了规范库定义的管理,经常这样做: . |-- cds.lib ------------- ...
- 29 面向对象编程 static 关键字
补充:static 代码 // static public class Student{ private static int age; // 静态的变量 多线程 private double sco ...
- 一比一还原axios源码(四)—— Axios类
axios源码的分析,到目前为止,算上第0章已经四章了,但是实际上,还都没有进入axios真正的主线,我们来简单回顾下.最开始我们构建了get请求,写了重要的buildURL方法,然后我们处理请求体请 ...
- BSOJ6388题解
看上去就很神秘...考虑建出图论模型. 我们将一张牌的两面 \(a,b\) 连一条边. 考虑一个连通块的意义是什么. 边是一张牌,容易发现,如果连通块是一棵树,那么选择一个根节点相当于可以打出除了根节 ...
- 7月3日 Django 头像预览、用户上传文件操作、logging、debug_tool_bar
1. 注册功能 1. 头像预览 //头像预览 $('#id_avatar').change(function () { console.log(this.files[0]) //找到选中的头像文件 v ...
- Golang之框架篇-Windows环境bee工具运行beego
bee工具简介及好处 bee 工具是一个为了协助快速开发 beego 项目而创建的项目,通过 bee 你可以很容易的进行 beego 项目的创建.热编译.开发.测试.和部署. 强烈推荐新手或J ...
- 说说&和&&的区别?
&和&&都可以用作逻辑与的运算符,表示逻辑与(and),当运算符两边的表达式的结果都为true时,整个运算结果才为true,否则,只要有一方为false,则结果为false.
- 使用Spring通过什么方式访问Hibernate?
在Spring中有两种方式访问Hibernate: 控制反转 Hibernate Template和 Callback. 继承 HibernateDAOSupport提供一个AOP 拦截器.
- Javascript Range对象的学习
Range对象有几个特别难理解的属性,这里学习总结下 Range.startOffset:返回一个表示 Range 起点在 startContainer 中的位置的数字.此属性的值与Range.sta ...