DB2数据库的常用语句之前已经为大家介绍了很多,本文将继续讲述DB2数据库常用语句。

1、统计表中员工的薪水在4000-6000之间的人数

select count(*)as 人数

from employee

where salary between 4000 and 6000

2、查询表中的同一部门的职工的平均工资,但只查询”住址”是”上海市”的员工

select avg(salary) avg_sal,dept

from employee

where addr like ‘上海市%’

group by dept

3、将表中住址为”上海市”的员工住址改为”北京市”

update employee

set addr like ‘北京市’

where addr like ‘上海市’

4、查找业务部或会计部的女员工的基本信息

select emp_no,emp_name,dept

from employee

where sex=’F’and dept in (‘业务’,’会计’)

5、显示每种产品的销售金额总和,并依销售金额由大到小输出

select prod_id ,sum(qty*unit_price)

from sale_item

group by prod_id

order by sum(qty*unit_price) desc

6、选取编号界于’C0001’和’C0004’的客户编号、客户名称、客户地址

select CUST_ID,cust_name,addr

from customer

where cust_id between ‘C0001’ AND ‘C0004’

7、计算出一共销售了几种产品

select count(distinct prod_id) as ‘共销售产品数’

from sale_item

8、将业务部员工的薪水上调3%

update employee

set salary=salary*1.03

where dept=’业务’

9、由employee表中查找出薪水最低的员工信息

select *

from employee

where salary=

(select min(salary )

from employee )

10、使用join查询客户姓名为”客户丙”所购货物的”客户名称”,”定单金额”,”定货日期”,”电话号码”

select a.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 ‘客户丙’

【编辑推荐】

    DB2数据库优化超有用的几条基本策略DB2数据库卸载的常用问题分析及方法DB2数据库所支持的外部文件格式