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 ...
随机推荐
- 【SQL】数据库运维实习工作经验
1.导入表格的时候回出现类型不对应的问题,T-SQL代码如下: USE zzzj2017 ALTER TABLE CJ ALTER COLUMN 付款时间 datetime 2.删除 USE s ...
- 从读写角度,带你了解数仓的IO基本框架
摘要:本文从读取和写入的角度分别描述了行存和列存的IO模型,并对文件结构做了简单介绍. 本文分享自华为云社区<GaussDB(DWS)基本IO框架>,作者: Naibaoofficial. ...
- 监督学习,无监督学习常用算法集合总结,引用scikit-learn库(监督篇)
why写这篇blog 最近在接触这方面的知识,但是找了许多的笔记,都感觉没有很好的总结出来,也正好当做是边学习,边复习着走.大佬轻喷.参考书目<python机器学习基础教程> 将分别从以下 ...
- java案例—遍历字符串
/*案例:遍历并打印字符串 需求:键盘录入一个字符串,使用程序在控制台遍历该字符串 分析:1.使用Scanner类获取输入的字符串 2.使用public char charAt(int index)方 ...
- 内网渗透----windows信息收集整理
一.基础信息收集 1.信息收集类型 操作系统版本.内核.架构 是否在虚拟化环境中,已安装的程序.补丁 网络配置及连接 防火墙设置 用户信息.历史纪录(浏览器.登陆密码) 共享信息.敏感文件.缓存信息. ...
- 从零开始,开发一个 Web Office 套件(12):删除文字 & 回车换行
这是一个系列博客,最终目的是要做一个基于 HTML Canvas 的.类似于微软 Office 的 Web Office 套件(包括:文档.表格.幻灯片--等等). 博客园:<从零开始, 开发一 ...
- Docker容器入门实践
Docker 是一个开源项目,诞生于 2013 年初,最初是 dotCloud 公司内部的一个业余项目.它基于 Google 公司推出的 Go 语言实现. 项目后来加入了 Linux 基金会,遵从了 ...
- cute
环境准备 将靶机导入后将网络设置为NAT kali:192.168.0.102 cute:192.168.0.107 端口扫描 使用nmap对靶机进行端口扫描 nmap –A –p- 192.168. ...
- C#: .net序列化及反序列化 [XmlElement(“节点名称”)] [XmlAttribute(“节点属性”)] (上篇)
.net序列化及反序列化 序列化是指一个对象的实例可以被保存,保存成一个二进制串,当然,一旦被保存成二进制串,那么也可以保存成文本串了.比如,一个计数器,数值为2,我们可以用字符串"2&qu ...
- 如何规划一台 Linux 主机,步骤是怎样?
1.确定机器是做什么用的,比如是做 WEB .DB.还是游戏服务器.不同的用途,机器的配置会有所不同. 2.确定好之后,就要定系统需要怎么安装,默认安装哪些系统.分区怎么做. 3.需要优化 ...